Coldbox 4.0 - CBJavaLoader Issue

I recently installed cbjavaloader using the cli. I believe I followed the instructions:

I placed this in the ColdBox.cfc
javaloader = {
// The array paths to load
loadPaths = getJars( getDirectoryFromPath( getCurrentTemplatePath() ) & “lib” ),
// Load ColdFusion classes with loader
loadColdFusionClassPath = false,
// Attach a custom class loader as a parent
parentClassLoader = “”,
// Directories that contain Java source code that are to be dynamically compiled
sourceDirectories = [],
// the directory to build the .jar file for dynamic compilation in, defaults to ./tmp
compileDirectory = getDirectoryFromPath( getCurrentTemplatePath() ) & “model/javaloader/tmp”,
// Whether or not the source is trusted, i.e. it is going to change? Defaults to false, so changes will be recompiled and loaded
trustedSource = false
};

However now I get this error on app load:# Variable GETJARS is undefined.

getJars is a function that returns an array.

try loadPaths = [expandPath(’./lib/’) & ‘name_of_jar_file.jar’],

and it should work. I had this exact problem myself.

know that loadPaths should be an array of each jar to be loaded

Thank you for answer!

There are quite a few jars needing to be loaded. I was hoping javaloader would have been able to dynamically load them on application start.

The docs for that are wrong. The getJars() helper method is in the ModuleConfig for the module. You will need to build your own array of jars in the ColdBox config.

See this related ticket:
https://ortussolutions.atlassian.net/browse/CCM-12

We’d love to get some pull requests to get this ironed out :slight_smile:

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Thank you!

Love the quick replies. Definitely plan on contributing more once i learn what I am doing :slight_smile:

What’s up, Benson! I just got this error and lo and behold, here you are! haha

Hi Brad,

Is there any documentation/procedures on how we go about handling pull requests for Ortus Solutions?
Also, I attempted to look at the related ticket, however it brought me to a login screen. I attempted to log in with my Google credentials but it did nothing. Are we supposed to ask for permission or is it not supposed to take us to this location or are we allowed to created a new account to see your tickets?

I just want to be sure to follow the process.

Thank you,
Ryan Hinton

Ryan, you can learn how to sign up for JIRA here:

http://blog.coldbox.org/blog/how-to-create-a-jira-account-and-enter-coldbox-tickets

I have not documented the pull request process since it’s pretty much just the standard Git process:

  1. Fork the repo on Github
  2. Clone it locally
  3. Branch from development
  4. commit and push your changes on that branch
  5. Create pull request via Github website
    Please ask if you have any more questions.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Excellent. Thanks, Brad!

Hi Brad,

I was just coming back to this and signed up with a Jira account.
I received the following error message. Maybe this issue no longer exists?

The error image did not paste in. Had to attach it as a file.

Thanks.

The image showed up in the first message for me. Looks like the permissions on that project weren’t set to be open. Please try again.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Awesome! Thank you, Brad!

I have a solution, but need to think about where the getJars method should be placed. Right now, I threw it into the Coldbox.cfc just so I was able to get it up and running right away for our needs here.
Would you have a suggestion as to where it should be placed?

Thank you,
Ryan Hinton

My preferences are documented in CCM-12 and are that you wouldn’t need to use that method at all, but rather the module would handle it for you :slight_smile:

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Here is what I have.

  1. getJars() method.
  2. Example of how I used it: javaLoader = { loadPaths = getJars(expandPath(’./lib/’))}

Thank you,
Ryan

// JavaLoader settings
/**
@hint Get an array of jar/class files.
/
private array function getJars(
required string dirPath,
string filter = "
.jar,*.class"
) {
if(not directoryExists(arguments.dirPath)) {
throw(message=“Invalid library path”, detail=“The path is #arguments.dirPath#”, type=“JavaLoader.DirectoryNotFoundException”);
}

return directoryList(arguments.dirPath, true, “array”, arguments.filter, “name desc”);
}
javaloader = {
// The array paths to load
loadPaths = getJars(expandPath(’./lib/’)), // The supposed alternative to using getJars() is: [expandPath(’./lib/’) & ‘name_of_jar_file.jar’];
// Load ColdFusion classes with loader
loadColdFusionClassPath = false,
// Attach a custom class loader as a parent
parentClassLoader = “”,
// Directories that contain Java source code that are to be dynamically compiled
sourceDirectories = [],
// the directory to build the .jar file for dynamic compilation in, defaults to ./tmp
compileDirectory = getDirectoryFromPath( getCurrentTemplatePath() ) & “model/javaloader/tmp”,
// Whether or not the source is trusted, i.e. it is going to change? Defaults to false, so changes will be recompiled and loaded
trustedSource = false
};

Ah OK, makes sense! :slight_smile:

I will check it out.

Thank you!
Ryan

I’ve just hit this issue converting a site to CB 4.1.0. Seems like the easiest way to specify an array of jars in a folder is to copy the core of the getJars method:

javaloader = {
loadPaths = directoryList( expandPath("./includes/java/"), true, “array”, “*.jar”, “name desc” )
};