Is it possible to get a second instance of the javaloader plugin?

Running CB3.0. And CF8.

Is it possible to get a second instance of the javaloader plugin?

A. Here is a simple example to illustrate the problem I'm having. I
wrote this in a view with production settings.

// Code

<cfset javaloader1 = getPlugin("JavaLoader",false,true)>
<cfset javaloader2 = getPlugin("JavaLoader",false,true)>

<cfset javaloader1.setup( listToArray(ExpandPath("/files/

<cfdump var="#javaloader1.GETURLCLASSLOADER().getURLS().next().toSTring
<cfdump var="#javaloader2.GETURLCLASSLOADER().getURLS().next().toSTring

// Output


B. My intention for javaloader1 and javaloader2 is: get the javaloader
plugin, it's not a custom plugin, and yes I want a new instance of it.

I then setup javaloader1 with the path to the file.

When I dump the info, both javaloader1 and javaloader2 have the same
information. If new instances had been created, this shouldn't be the

Thank you,

Hi Gabriel,

May I ask, why you need two instances of javaloader?

The purpose of the java loader is that you can point to a set of java jar’s or classes your application will use. Usually, at startup you point the java loader to what java classes to load. Then you can just use it throughout your application.

What is the exact use case for this?


I. I have two plugins. PluginA is a delimited file plugin
(reads,writes delimited files). PluginB is a string case plugin
(converts strings to Titlecase, Sentencecase). Independently, they
work and each plugin has a jar file that it uses functionality from.

The problem arises when PluginA makes a call to PluginB. Both plugins
"setup" their jar files with javaloader in the plugin's init. Because
only one javaloader exists, it will only have a reference to one of
the jars for both plugins. So when I try to create objects from those
jars, it will fail for one of the plugins as the classes won't be

II. However, I have found a workaround. My current workaround is to
create the objects I need from those jars on init right after java
loader is "setup". So now in the plugin's init function, I:

init() {
- Get javaloader plugin
- "Setup" javaloader with this plugin's jar
- Create objects from that jar that are used in the public functions

III. I thought about loading everything at startup but I really liked
the idea of the plugins taking care of loading what they needed
themselves and only when they were actually in use.

- Gabriel

Good point.

I just added two tickets for this enhancement and did a simple commit. Going to unit test it now.

Two new methods:

  1. getLoadedURLs() to get a report of all the loaded URLs in the class loader
  2. appendPaths(dirPath,filter) To append resources to load in the same classloader.

Please try them out on SVN and let me know.

These are on SVN now, check them out.

Appending works if javaloader is already loaded in the server scope.
Fails otherwise.

One option is to have the append function check if javaloader has been
loaded, and, if it hasn't, load it using the first location as the

That way, you can use the "setup" function if you're loading
everything at once. If you're loading "a la cart", like in mulitple
plugins that may or may not be needed, you can just use "appendPaths"
knowing that it will "setup" if needed.

- Gabriel

Done in SVN!!

Very cool and it's working well. Thank you!