Lucee jar problem (NoClassDefFoundError)

Hey everyone,

We have been developing with Lucee for a year now and in general it works very nice. I’ve to say that sometimes it’s difficult to find some documentation related to software in Lucee. But now for the problem we are having.

We try to convert Docx to PDF. We didn’t find any tags inside coldfusion/lucee that could do this. So the next solution is to have a JAR file that can be called inside Lucee. In the past we have used Docx4j within Coldfusion. This worked good, but also a lot of trouble to get it working. And newer versions didn’t work.

Now we use Lucee and I get problem after problem. For now I will talk about the first thing I tried and really want to get working inside Lucee.

I’ve found a library here:

This is a simple library that combines other librarys to get a good conversion to PDF. It can also work as a standalone version through windows console. THIS WORKS. I can fire a windows console command and it automatically converts a Docx to PDF.

So the next step is to get it to work inside Lucee. I’ve add the jar file inside: “WEB-INF\lucee\lib”. If I go to the Lucee admin I can see that the jar file is “Active” (green). So it all looks OK. But when I try to call the function with the following code inside a cfscript tag:

    temp_File = createObject("java","java.io.File");
	temp_FileInputStream = createObject("java","java.io.FileInputStream");
	temp_FileOutputStream = createObject("java","java.io.FileOutputStream");
	temp_Converter = createObject("java","com.yeokhengmeng.docstopdfconverter.DocxToPDFConverter");

	input_stream = javacast("java.io.InputStream", temp_FileInputStream.init(temp_File.init("C:\conversie_diva_part2.docx")));
	output_stream = javacast("java.io.OutputStream", temp_FileOutputStream.init(temp_File.init("C:\conversie_diva_part2.pdf")));

    temp_Converter.init();

The last line gives an error. A “NoClassDefFoundError” error. I think this comes from a import inside a indirect class. But I’ve tried so many libraries / codes and everytime it gives an error like this. I’ve add so many dependencies (different versions etc) but always this error. Also something I find weird is that the jar file works on itself (all dependencies are inside) but not through Lucee.

So I think something is wrong with our Lucee / Java environment. But how can I know this? I would be very grateful if somebody can take a look at this and send me in a direction to do some tests. I’ve also tried jars/code from a working coldfusion page, but that doesn’t work either. And with the errors I get I cannot do much. I want to know what is failing because we want to continue working with Lucee.

I’ve upgrade Lucee to latest version. Test many jar versions. Read a lot of posts of other users. But nothing works for us. Please help if you have any idea.

Thank you in advance,

Roland

This is btw the full stack trace of the error we got

lucee.runtime.exp.NativeException: org/apache/poi/xwpf/converter/core/Options at
 java.lang.Class.getDeclaredConstructors0(Native Method) at
 java.lang.Class.privateGetDeclaredConstructors(Class.java:2671) at
 java.lang.Class.getConstructors(Class.java:1651) at
 lucee.runtime.reflection.storage.WeakConstructorStorage.store(WeakConstructorStorage.java:60) at
 lucee.runtime.reflection.storage.WeakConstructorStorage.getConstructors(WeakConstructorStorage.java:45) at lucee.runtime.reflection.Reflector.getConstructorInstance(Reflector.java:425) at lucee.runtime.reflection.Reflector.getConstructorInstance(Reflector.java:418) at lucee.runtime.reflection.Reflector.callConstructor(Reflector.java:807) at lucee.runtime.java.JavaObject.init(JavaObject.java:296) at lucee.runtime.java.JavaObject.call(JavaObject.java:222) at lucee.runtime.java.JavaObject.call(JavaObject.java:259) at lucee.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:756) at lucee.runtime.PageContextImpl.getFunction(PageContextImpl.java:1698) at views.instellingen.default_cfm$cf.call(/views/instellingen/default.cfm:44) at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:908) at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:833) at lucee.runtime.PageContextImpl.doInclude(PageContextImpl.java:817) at framework.one_cfc$cf.udfCallb(/framework/one.cfc:1877) at framework.one_cfc$cf.udfCall(/framework/one.cfc) at lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:107) at lucee.runtime.type.UDFImpl._call(UDFImpl.java:357) at lucee.runtime.type.UDFImpl.call(UDFImpl.java:226) at lucee.runtime.type.scope.UndefinedImpl.call(UndefinedImpl.java:771) at lucee.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:756) at lucee.runtime.PageContextImpl.getFunction(PageContextImpl.java:1698) at framework.one_cfc$cf.udfCall5(/framework/one.cfc:870) at framework.one_cfc$cf.udfCall(/framework/one.cfc) at lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:107) at lucee.runtime.type.UDFImpl._call(UDFImpl.java:357) at lucee.runtime.type.UDFImpl.call(UDFImpl.java:226) at lucee.runtime.ComponentImpl._call(ComponentImpl.java:668) at lucee.runtime.ComponentImpl._call(ComponentImpl.java:586) at lucee.runtime.ComponentImpl.call(ComponentImpl.java:1972) at lucee.runtime.listener.ModernAppListener.call(ModernAppListener.java:419) at lucee.runtime.listener.ModernAppListener._onRequest(ModernAppListener.java:221) at lucee.runtime.listener.MixedAppListener.onRequest(MixedAppListener.java:43) at lucee.runtime.PageContextImpl.execute(PageContextImpl.java:2405) at lucee.runtime.PageContextImpl._execute(PageContextImpl.java:2395) at lucee.runtime.PageContextImpl.executeCFML(PageContextImpl.java:2363) at lucee.runtime.engine.Request.exe(Request.java:44) at lucee.runtime.engine.CFMLEngineImpl._service(CFMLEngineImpl.java:1091) at lucee.runtime.engine.CFMLEngineImpl.serviceCFML(CFMLEngineImpl.java:1039) at lucee.loader.engine.CFMLEngineWrapper.serviceCFML(CFMLEngineWrapper.java:102) at lucee.loader.servlet.CFMLServlet.service(CFMLServlet.java:51) at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) at org.apache.coyote.ajp.AbstractAjpProcessor.process(AbstractAjpProcessor.java:844) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.NoClassDefFoundError: org/apache/poi/xwpf/converter/core/Options ... 65 more Caused by: java.lang.ClassNotFoundException: org.apache.poi.xwpf.converter.core.Options not found by docs.to.pdf.converter.1.8 [79] at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1550) at org.apache.felix.framework.BundleWiringImpl.access$200(BundleWiringImpl.java:79) at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1958) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 65 more

did you try passing in an array of paths to the jars required as the third argument?

i.e.

createObject(“java”,“com.yeokhengmeng.docstopdfconverter.DocxToPDFConverter”,
[‘.\libs\jar1.jar’, ‘.\libs\jar2.jar’]);

Hey,

Thanks for the quick reply! I will try this immediately.

But for you information. Isn’t it enough that the libraries are imported inside the class file?

Like: import org.apache.poi.xwpf.usermodel.XWPFDocument;

Thanks!

it’s depends, usually if you look at a java examples, it will often import a range of classes

for example with that class, here is a example

see all the imports required for this example? you need them too

you may have a poi jar bundle which has them all, but if not… you’ll get the error

If I understand you correctly then you explain that you need to have all the jar files which are used as import. That I understand, those are all the dependencies. The library I’m using is 1 jar file. It contains a lot of jar files inside. See following image:

(Note that not all jar files could fit inside the image)

I even tried to remove all the jar files inside and add them separately. Still get the same error then.

What I think the problem is, is that indirect import of libraries doesn’t work with Lucee.

But how can I confirm what the problem is, this is so difficult to grasp.

BTW I tried to add the third parameter but still gives me the same error. Perhaps because now all the jar files are inside again. So perhaps if I remove them from the jar file and then add al the 30 or so jar files as a parameter, maybe then it works. But still inside the classes a import is used. So if this gives an error then this wont go away.

But I can’t be the only one trying to get a jar file with imports to work.

So hope you can shine some light on this, thanks!

can you post a link to the actual library? I’m sure somebody can point you in the right direction

Yes I already did in my first post, but here it is again:

Thanks!

Hi @DrunkenMoose,
i tested the library and it worked fine for me.

How did you compile the project? (i had to add some build-properties to the pom.xml)
After compiling i received a jar with about ~ 50MB.
I placed it in tomcat\lucee-server\context\lib, to test it fast.

Here is also the code which i used to test:

<cfscript>
	testFile = ExpandPath("test.docx");
	testOutFile = ExpandPath("test.pdf");
	
	temp_File = createObject("java","java.io.File");
	temp_FileInputStream = createObject("java","java.io.FileInputStream");
	temp_FileOutputStream = createObject("java","java.io.FileOutputStream");
	temp_Converter = createObject("java","com.yeokhengmeng.docstopdfconverter.DocxToPDFConverter");
	
	input_stream = javacast("java.io.InputStream", temp_FileInputStream.init(temp_File.init(testFile)));
	output_stream = javacast("java.io.OutputStream", temp_FileOutputStream.init(temp_File.init(testOutFile)));
	
	temp_Converter.init(input_stream, output_stream, true, true);
	temp_Converter.convert();
</cfscript>

I guess you have a compiling problem. Your jar dont seem to contain all Classes/Librarys.
If you want i can upload my compiled version of the library.

1 Like

Wow David many thanks for taking a look at it. I’m currently not at home so I cannot take a look at it now. But when I get home I will immidiatly take a look. If you could upload your compiled library somewhere then that would be very helpfull. I have to say your code looks exactly like a test I did so it must be the library.

Many thanks again! If it works I will update this post for everybody to see!

I dont know how you builded the jar, but i used Idea and added build-nodes to the pom.
I compiled with Java 1.8, i dont know if you will face some issues here, because the ReadMe says its not tested. (But my testcase worked fine)
Anyway, here is the Link to the compiled version:
https://we.tl/FDknZveEVq

Yes i took your code(its not wrong) and just looked at the Java-Class and adjusted to get it running.

2 Likes

You are correct.

When you try to load a class that is not in the classpath yourself, you get a ClassNotFoundException.

When you get the NoClassDefFoundError, it means that the class that you are trying to load yourself is found, but it has a dependency on a class that is not found.

1 Like

could that error message message be improved to reflect(sic) that? that’s quite a good explanation

It’s a Java thing, not a Lucee thing:
https://docs.oracle.com/javase/7/docs/api/java/lang/NoClassDefFoundError.html

See also
https://dzone.com/articles/java-classnotfoundexception-vs-noclassdeffounderro

Hey everybody,

Thanks for all the info on the subject. Indeed this error gave me an idea that something is not going right with the dependencies, but the weird thing is that I could find the class related to the error inside the jar file. I even included the jar file on it own, but still gave me the same error.

But then I did the following step and a miracle happend:

  • Removed all jar files from lib folder
  • Downloaded and placed the given jar file from David inside lib folder
  • Restarted the Lucee service through windows
  • Restarted Lucee inside admin page
  • Made page with given code by David.
  • Placed test.docx inside root folder of website (because of expandpath)
  • Called the page and tada a beautiful PDF came out. Also damn fast.

So thanks to David for your work .If I could give some bucks worth a coffee then give me link (Paypal please)! Just little thanks for the trouble. Now I know the library worked and Lucee also works so that’s a relieve. I can also inspect this Jar file for more clues on how it works correctly and what went wrong.

https://lucee.daemonite.io/t/lucee-jar-problem-noclassdeffounderror/3834/8?u=modius

Thanks!

2 Likes

And an other thing: If I compare my old jar file and yours then I see a lot of files missing. I do have class files with the folder names: “com”, “META-INF”, “org”, “src”, and other than that a lot of jar files. But nothing else.

You where talking about it not being compiled. This may sound as a stupid question: but I should have compiled the jar file through eclipse (or maybe even windows console?) before trying to use it inside Lucee? It’s just the way how I downloaded it from github. Thought it should work as is, because the windows console version of this jar file did work for me. Just not calling it through cfscript. Still sorta searching my way through all of this. Is there maybe a Lucee page explaining Jar files that I have missed? Or is it more of a Java thing, separate from Lucee? Still many thanks!

maybe the documentation could be improved as @DrunkenMoose noted he struggled to find
documentation which helped him with this process?

Nice that i could help and its working now for you :slight_smile:

I dont know how they compiled their jar (which you find under github → releases), but i think thats not a standard way to package/compile a jar. I guess Lucee cant handle jar in jar-files. In my compiled jar, you find all dependencies compiled as classes and not as a jar.
Maybe thats the problem, but i dont know exactly.

1 Like