We’re on Lucee 5.2.7.63 and experiencing some bad issues with loading in JAR’s in our Lucee app via CreateObject. We are not able to load ANY JAR-file - getting the below message everytime:
cannot load class through its string name, because no definition for the class with the specified name [JAR-functionname] could be found caused by (java.lang.ClassNotFoundException:JAR-functionname not found by lucee.core [64];java.lang.ClassNotFoundException:JAR-functionname;java.lang.ClassNotFoundException:JAR-functionname;)
Are you using the Lucee spreadsheet library by any chance? If so is that giving the same error? By default that will load the POI etc jars in Lucee 5.x using createObject() but it can be configured to use JavaLoader.
Hi Julian, well, it seems that our JavaLoader being saved to a server variable for now was the culprit. Even a restart of Lucee didn’t clear the server-scoped object of loaded JAR’s. This was never an issue with ColdFusion. The JAR’s are for creating QR-codes and our own JAR’s with functions needed to create SPSS-files. Furthermore we have created a JAR that connects to a certain service, but they were not loaded either. Strange thing was that if I loaded the JAR somewhere in a CFC it went fine, doing the same operation in a CFM didn’t work. Anyways, Monday may be better, but porting a large webapp to Lucee from ACF is certainly proving to be difficult - way more so than I expected at first
Strange. I use JavaLoader quite a bit in Lucee and haven’t had any issues putting instances in the server scope (including with the Spreadsheet lib). Here’s how I generally code my JAR wrappers’ init() methods (where the jars are in the same directory as the wrapper):
function init( javaLoaderPath=variables.javaLoaderPath ){
var javaLoaderName = "myLoader";
if( !server.keyExists( javaLoaderName ) ){
var paths = [];
paths.append( getDirectoryFromPath( getCurrentTemplatePath() ) & "my.jar" );
server[ javaLoaderName ] = New "#arguments.javaLoaderPath#"( paths );
}
return this;
}
I sympathise. I wrote a whole series of blog posts a few years back on the woes we had transitioning to Railo, then Lucee. It all depends on which features you use. Good luck and shout if you need help.
That is being loaded into the server variable. What are we doing wrong here? I get the error-message that the desired classes are not available.
Hmmm, if I skip the check in Application.cfc then the server-variable will be reloaded on each onApplicationStart. Is that bad? At least it works for now, as Lucee doesn’t seem to clear the server variables on Lucee Windows restart. Do you experience the same @Julian_Halliwell?
I think there must be something else going on that’s specific to your set up, Seb. As far as I’m aware server variables do not survive Lucee restarts - I’m not sure how they could without you manually serializing them to disk?
Personally I wouldn’t put this kind of logic in Application.cfc. I always use encapsulated wrappers, i.e. dedicated components which handle the loading/server scope checks for me and just let me call the classes/methods I need at the points in the app where I need them. Again, the Spreadsheet lib is an example of this.
I’m happy to test the specific jars you’re working with on my own setup if they can be shared privately or otherwise.
Hi @Julian_Halliwell, you’re right, of course, I’ve refrained from restarting Lucee, because of this: [LDEV-1763] - Lucee Gives me 3-5 minutes downtime every time, so for now the variable is reset onApplicationStart. But happy to say all stuff now seems to work as on ACF. Incorporating JAR’s into Lucee webapps is fun and powerful!