Using JavaLoader

Hi folks,

I'm having troubles understanding how to implement the JavaLoader plugin. It appears the examples need updating in docs - http://wiki.coldbox.org/wiki/Plugins:JavaLoader.cfm - so I was wondering if someone can share best practices as to how/where to configure and setup the array of Jars and then how to call. I would ideally like to use JavaLoader with DI so I can access it within my models and handlers.

Thanks in advance.

Nolan

I usually wrap up my external jars as coldbox plugins. Then the rest of the app talks to the plugin.

For example, I use one of the apache commons libraries and so in my plugin’s init(), I have something like

<cfset controller.getPlugin(“JavaLoader”).appendPaths( ExpandPath(“my/path/to/jar/apachecommonslang/”) )>

<cfset variables.StringEscapeUtilsObj = controller.getPlugin(“JavaLoader”).create(“org.apache.commons.lang.StringEscapeUtils”)>

Then within my plugin, I can get as funky as I want. I can create a function to return one of the jar objects directly. Or I can create a function that uses one of the jar objects and has my own logic mixed in as well.

  • Gabriel

Hi Gabriel,

That’s a great approach. Thanks for sharing!

Nolan

Hi Gabriel,

I was able to get this to work. Thanks for the tip.

Question… in my handler I am dumping out the instantiated plugin (and jar) to see what methods are contained within. With CFDump (or another approach) is there a way to introspect which methods are public vs private?

Thanks.

Nolan

I don’t know how to determine that programmatically. I’ve only ever looked at the documentation for a given library to figure out what methods I could use.

  • Gabriel