Lucee Docker: I cant load bundled jars

Using Lucee 5.3.9.160 in Docker in WSL:Ubuntu-20.04 under Windows 10

Hi. I must be missing something basic regarding loading jars.

I am playing with using the Jedis jar in Lucee because I want to experiment with redisJson and Search, etc.

In my Dockerfile I copy the jedis-4.3.0-m1.jar to
/opt/lucee/server/lucee-server/bundles/jedis-4.3.0-m1.jar
and in the Admin Server and Web contexts Bundles (jars) section, the jar is visible with a status of “loaded”.

Now, since it is “loaded” I thought I should be able to import it like this:

Jedis = createObject( "java", "redis.clients.jedis.Jedis")
writeDump(var=Jedis,label="Jedis");

But that throws:

Lucee 5.3.9.160 Error (lucee.commons.lang.ClassException)
Message	cannot load class through its string name, because no definition for the class with the specified name [redis.clients.jedis.Jedis] could be found caused by (java.lang.ClassNotFoundException:redis.clients.jedis.Jedis not found by lucee.core [49];java.lang.ClassNotFoundException:redis.clients.jedis.Jedis;)

However, if I do this (give it the explicit path) it works:

Jedis = createObject( "java", "redis.clients.jedis.Jedis", "/opt/lucee/server/lucee-server/bundles/jedis-4.3.0-m1.jar" )
writeDump(var=Jedis,label="Jedis");

However, if I then create the class via .init() as per:

Jedis = createObject( "java", "redis.clients.jedis.Jedis", "/opt/lucee/server/lucee-server/bundles/jedis-4.3.0-m1.jar" ).init()

it throws:

Lucee 5.3.9.160 Error (java.lang.NoClassDefFoundError)
Message	Could not initialize class redis.clients.jedis.CommandObjects

Furthermore …

If I import this class:

variables.jedisPool = createObject("java", "redis.clients.jedis.JedisPool", "/opt/lucee/server/lucee-server/bundles/jedis-4.3.0-m1.jar")

it throws:


Lucee 5.3.9.160 Error (java.lang.NoClassDefFoundError)
Message	org/apache/commons/pool2/impl/GenericObjectPool

The implementation is:

redis.clients.jedis
  Class JedisPool
    java.lang.Object
      org.apache.commons.pool2.BaseObject
        org.apache.commons.pool2.impl.BaseGenericObjectPool<T>
          org.apache.commons.pool2.impl.GenericObjectPool<T>
            redis.clients.jedis.util.Pool<Jedis>
              redis.clients.jedis.JedisPool

all of which is why I was thinking that if the Jedis jar was being loaded from via Lucee bundles it would have everything it needed? Or maybe this is an entirely different error.

Maybe I also need to put the commons-pool2-2.11.1.jar in the Lucee bundles folder too?

My lack of Java expertise is telling here…

Can anyone shed any light, please?

Thanks,
Murray

you have to place the jar file to /lib/ folder and restart the lucee.

Also, you can use this.javaSettings in Application.cfc to load the jar files from the folders which contain the custom jar files

Thank you!

Re: The info on the Custom Jars doc page…

In the Docker Tomcat version it seems that
{local web context}/WEB-INF/lucee/lib/
translates into
/usr/local/tomcat/lib/
so in the Dockerfile
COPY jedis-4.3.0-m1.jar /usr/local/tomcat/lib/jedis-4.3.0-m1.jar

and
{Lucee Installation Folder}/lucee-server/context/lib/
translates into
/opt/lucee/server/lucee-server/context/lib/
so
COPY jedis-4.3.0-m1.jar /opt/lucee/server/lucee-server/context/lib/jedis-4.3.0-m1.jar

depending on which context you want it in.

Now I understand. Thanks.
Murray

On a separate note, the other part of my question (which perhaps is not to do with Lucee?):

When I do this:

jedis = createObject( "java", "redis.clients.jedis.Jedis").init()

it throws:

Lucee 5.3.9.160 Error (java.lang.NoClassDefFoundError)
Message	Could not initialize class redis.clients.jedis.CommandObjects

I am guessing the Jedis constructor is calling the redis.clients.jedis.CommandObjects class. Given redis.clients.jedis.Jedis is now being found and the constructor called, why wouldn’t Java find the redis.clients.jedis.CommandObjects class? The Jedis javadocs (and the pathname) show it as being part of the same redis.clients.jedis package.

No joy from Dr Google.

Thanks again,
Murray

@flowt-au
why wouldn’t Java find the redis.clients.jedis.CommandObjects class

I think lucee found the redis.clients.jedis.CommandObjects class because Creating object didn’t throw an error.

variables.CommandObjects = createObject("java", "redis.clients.jedis.CommandObjects");

But the error thrown on creating constructor (init()) for this class

variables.CommandObjects = createObject("java", "redis.clients.jedis.CommandObjects").init();

Can you please create a ticket in Jira for this issue? https://luceeserver.atlassian.net/

Done: https://luceeserver.atlassian.net/browse/LDEV-4170

Thanks

1 Like