I’d like to use some java class in my app. On coldbox site I see
`
All you have to do is drop any jar or class file in the lib folder and it will be available via createobject(“java”) anywhere in your app.
`
I have dropped a jar in the lib folder, but I cannot instantiate it. Seems is not loaded. Is there something I should add to my config.cfc or application.cfc to make it works?
Check and make sure your Application.cfc has this:
// JAVA INTEGRATION: JUST DROP JARS IN THE LIB FOLDER
// You can add more paths or change the reload flag as well.
this.javaSettings = { loadPaths = [ “lib” ], reloadOnChange = false };
Thanks!
~Brad
ColdBox Platform Evangelist
Ortus Solutions, Corp
E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com
Yes, now it works! In modules is the same? I should add a setting to each module that contains a lib folder?
If a module has a jar file of its own, you would need to add its lib path to the Application.cfc setting. I don’t really care for this since it spreads our your configuration and makes your modules not just “plug and play” but this.javaSettings is a CF feature so we have little control over it.
If you have a lot of pluggable modules that have their own jar files, look into the java loader module. It allows a module to register its own jars programatically so it’s all self contained.
https://github.com/ColdBox/cbox-javaloader/blob/master/modules/cbjavaloader/instructions.md
Thanks!
~Brad
ColdBox Platform Evangelist
Ortus Solutions, Corp
E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com
Oh, I should add-- here’s an example of a module that uses the java loader module. This line of code is where it appends its lib path in on startup.
https://github.com/ColdBox/cbox-antisamy/blob/master/modules/cbantisamy/ModuleConfig.cfc#L41
If you want to use the java loader module, add it as a dependency to your module’s box.json’s that require it, and also add it as a dependency in each module’s moduleConfig.cfc so it gets loaded first.
Thanks!
~Brad
ColdBox Platform Evangelist
Ortus Solutions, Corp
E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com