TESTBOX - Java issues again

Okay, I have code that works fine in the site, at runtime. (Yes, this is an up-to-date Coldbox site.)

Basic structure is this:
root\html
root\html (all stuff)
root\html\testbox
root\html\tests
root\html\tests\application.cfc

My site (html\application.cfc) has this entry:

The app.cfc in \tests has this:

	this.javaSettings = {
		loadPaths               : [ expandPath( "./lib" ) ],
		loadColdFusionClassPath : true,
		reloadOnChange          : false
	};

The tests\application.cfc has this, note the path difference.

	this.javaSettings = {
		loadPaths               : [ expandPath( "../../../lib" ) ],
		loadColdFusionClassPath : true,
		reloadOnChange          : false
	};

The jar gets loaded fine for the app. Today, instead of running a SINGLE test, I did a Run All. Got the error below, changed the path. The expandPath() for the tests\application.cfc acts differently between run JUST the test file vs. Run All. They can’t both work, unless I knock out a “/…” entry. Then the other doesn’t work.
image

Suggestions, anyone? Other than hard-coding the path? (Which I just tested, and does solve the issue.)

Unless I am wrong, your question boils down to: “How do I set a path relative to Application.cfc and not relative to the currently execution path?”

You can choose either of these methods, they should work for you:

  • Use getDirectoryFromPath( getCurrentTemplatePath() ) as an appRoot variable.
  • Use ./ to prepend your lib path.

Something like this (for the tests/ directory):

APP_ROOT = getDirectoryFromPath( getCurrentTemplatePath() );
this.javaSettings = {
    loadPaths               : [ expandPath( APP_ROOT & "/lib" ) ],
    loadColdFusionClassPath : true,
    reloadOnChange          : false
};

OR

this.javaSettings = {
    loadPaths               : [ expandPath( "./../lib" ) ],
    loadColdFusionClassPath : true,
    reloadOnChange          : false
};

Well, @MichealBorn I simply do NOT know why I didn’t think of that. Derp. Was so focused on the java issue… Grrrr.

[ expandPath(getDirectoryFromPath(getCurrentTemplatePath()) & “…/lib” ) ]

…solved it.

Thanks for waking me up. You’d think 20+ years of CF and I’d have solved that on my own.

1 Like

It happens. I have the luxury of a few more Ortus projects to grab precedence from. :grin:

We should also add this.javaSettings to our app templates so anyone who runs coldbox create app in the future to jumpstart a Coldbox app won’t have to struggle through this same configuration issue.