Where to add jar file to express install?

Where do you add a custom jar to the express install?

cannot load class through its string name, because no definition for the class with the specified name [mytestjar] could be found caused by (java.lang.ClassNotFoundException:influxdb-2.5.2 not found by lucee.core [64];java.lang.ClassNotFoundException:influxdb-2.5.2;)

I have tried lucee-install/lib and webapps/WEB-INF/lucee/lib but it is not finding it.

Try placing the jar in the same directory as your calling .cfm file and using:

object = CreateObject( "java", "myclass", ExpandPath( "./" ) );

You can also put any jars you want to implement in a path and load them into the Application.cfc using this.javaSettings.loadPaths, for example:

this.javaSettings.loadPaths = [getDirectoryFromPath(getCurrentTemplatePath()) & "lib/"];
this.javaSettings.reloadOnChange=true;

and then create your object wherever it is needed:

obj = createObject( 'java', 'com.path.to.myclass' );

That said, putting it into WEB-INF/lucee/lib should also allow you to find the class, so I suspect you may just have a bad call to get the class. For portability, however, I prefer to load jar’s in Application.cfc vs. putting them in the lib dir.

HTH

– Denny

1 Like

Just to note that this setting (along with watchInterval) doesn’t work in Lucee: once loaded you’re stuck with your classes until you restart the instance. Votes for the following would be welcome.

https://luceeserver.atlassian.net/browse/LDEV-800
https://luceeserver.atlassian.net/browse/LDEV-1551
https://luceeserver.atlassian.net/browse/LDEV-1528

2 Likes

Thank you all for your input. I got my 1st .Jar file loaded.

But then I tried another Jar and got this error. I am trying to use influxdb-java-2.8 from http://central.maven.org/maven2/org/influxdb/influxdb-java/2.8/

The OSGi Bundle with name [influxdb-java-2.8] is not available locally (/Volumes/Samsung USB/lucee-express-5.1.0.34/lucee-server/bundles) or from the update provider (http://release.lucee.org).

Unfortunately, I’m not a java expert so could anyone explain what I should do. If I compile the Jar myself locally will I get the same error? I just don’t want to have to go through all that if i’m going to get the same result of it not loading.

Thanks for any help you can offer.

As far as I can see there’s only one jar which contains all the classes you’ll need to load.

Can you post the code that’s producing the error?

Im just running this code:

<cfsetting showdebugoutput="yes">
<CFTRY>
     <CFSET influxdb = createObject('java','org.influxdb.InfluxDBFactory',['influxdb-java-2.8.jar'] )>
<CFCATCH TYPE="ANY">
     <CFDUMP var="#CFCATCH#">
</CFCATCH>
</CFTRY>

I figured out the OSGi error. I omitted the .jar extension when I typed it. Funny how little things can hang you up.

Now I get this error:

lucee.commons.lang.ClassException
cannot load class through its string name, because no definition for the class with the specified name [org.influxdb.InfluxDBFactory] could be found caused by (java.lang.ClassNotFoundException:org.influxdb.InfluxDBFactory not found by lucee.core [64];java.lang.ClassNotFoundException:org.influxdb.InfluxDBFactory;java.lang.UnsupportedClassVersionError:org/influxdb/InfluxDBFactory : Unsupported major.minor version 52.0;)
/Volumes/Samsung USB/lucee-express-5.1.0.34/webapps/ROOT/influxjava/test3.cfm:10

Any suggestions on “Unsupported major.minor version 52.0;” ?

I appreciate the help.

I was wrong. It seems it depends on 4 other jars being available:

https://mvnrepository.com/artifact/org.influxdb/influxdb-java/2.8

Try putting those in your folder along with the influxdb jar and then load them all using:

influxdb = CreateObject( "java", "org.influxdb.InfluxDBFactory", ExpandPath( "." ) );
dump( influxdb );

EDIT: To be clear, the script/template .cfm and jars should all be in the same folder.

If I load it via: influxdb = CreateObject( “java”, “org.influxdb.InfluxDBFactory”, ExpandPath( “.” ) );

Or explicitly name the jars

<CFSET configuration = createObject(‘java’,‘org.influxdb.dto.Query’,[‘converter-moshi-2.3.0.jar’,‘okhttp-3.9.1.jar’,‘okio-1.13.0.jar’,‘retrofit-2.3.0.jar’,‘logging-interceptor-3.9.1.jar’,‘moshi-1.4.0.jar’,‘influxdb-java-2.8.jar’] )>

still get that error.

cannot load class through its string name, because no definition for the class with the specified name [org.influxdb.dto.Query] could be found caused by (java.lang.ClassNotFoundException:org.influxdb.dto.Query not found by lucee.core [64];java.lang.UnsupportedClassVersionError:org/influxdb/dto/Query :

Unsupported major.minor version 52.0;java.lang.ClassNotFoundException:org.influxdb.dto.Query;)

Were you able to at least dump out the InfluxDBFactory class metadata using the code I gave you? That worked for me and gave me this:

I don’t have an influxdb server running to test the connect() method against though.

It didn’t, it should work right.

folder/file list:
converter-moshi-2.3.0.jar logging-interceptor-3.9.1.jar okhttp-3.9.1.jar retrofit-2.3.0.jar
influxdb-java-2.8.jar moshi-1.4.0.jar okio-1.13.0.jar test4.cfm

test4.cfm contains

<cfscript>
 influxdb = CreateObject( "java", "org.influxdb.InfluxDBFactory", ExpandPath( "." ) );
 dump( influxdb );
</cfscript>

57 PM

Updated java in terminal to 8 and it worked!

Lucee did not like Java 7.

How do I get to the methods in InfluxDB class once the factory is called? I’m missing something and I just cant get my head around it. Isn’t the factory suppost to create the instance with access to the classes?

 InfluxDBFactory = CreateObject( "java", "org.influxdb.InfluxDBFactory", ExpandPath( "." ) );
 influxdb = CreateObject( "java", "org.influxdb.InfluxDB", ExpandPath( "." ) );
 query = CreateObject( "java", "org.influxdb.dto.Query", ExpandPath( "." ) );
 dump(InfluxDBFactory);
 dump(influxdb)

 dbName = "test";
 InfluxDBFactory.connect('http://localhost', 'root', 'pass');
 query.init("select * from mymeesure", dbName );
 
InfluxDBFactory.query(query)

the code:

InfluxDBFactory.query(query)

Results in an error:

No matching Method for query(org.influxdb.dto.Query) found for org.influxdb.InfluxDBFactory

How do I use to the methods in InfluxDB class?

I’ve no prior experience with this database or API and don’t have it set up to test, but it looks like when you connect() to your database using the InfluxDBFactory it returns an influxDB object, which you then use to issue queries. So perhaps something like:

factory = CreateObject( "java", "org.influxdb.InfluxDBFactory", ExpandPath( "." ) );
dbObject = factory.connect( "http://localhost", "root", "pass" );
sql = "SELECT * FROM mymeesure";
dbname = "test";
myQuery = CreateObject( "java", "org.influxdb.dto.Query", ExpandPath( "." ) ).init( sql, dbname );
result = dbObject.query( myQuery );
dump( result );
1 Like

Man I can tell your a cool person. Thanks for helping me with that syntax. I’m startign to get my head around how to call the java objects.

I am thrilled it did something different and executed.

Got this when it executed so trying to figure that out next.

java.net.SocketTimeoutException: timeout

1 Like

Thank you so much for your help. I have it working now.

1 Like