Sure, so I’m not using a custom tag for this test version. For this, I’m just calling the Java function directly using <cfscript>.
(c:\inetpub\wwwroot\print_test\LuceeJavaxPrintTest.cfm)
<cfscript>
// Create an instance of your Java class
JavaXPrintTestInstance = CreateObject("java", "com.cigcustom.lucee.JavaxPrintTest");
message = JavaXPrintTestInstance.showPrintServices();
// Output the result
WriteOutput(message);
</cfscript>
Here is the error I get when running this .CFM in Lucee:
Lucee 6.0.1.83 Error (java.lang.NoClassDefFoundError)
Message javax/print/attribute/standard/Fidelity
Stacktrace The Error Occurred in
C:\inetpub\wwwroot\print_test\LuceeJavaxPrintTest.cfm: line 5
3: JavaXPrintTestInstance = CreateObject("java", "com.cigcustom.lucee.JavaxPrintTest");
4:
5: message = JavaXPrintTestInstance.showPrintServices();
6:
7: // Output the result
Java Stacktrace lucee.runtime.exp.NativeException: javax/print/attribute/standard/Fidelity
at com.cigcustom.lucee.JavaxPrintTest.showPrintServices(JavaxPrintTest.java:28)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at lucee.runtime.reflection.pairs.MethodInstance.invoke(MethodInstance.java:56)
at lucee.runtime.java.JavaObject.call(JavaObject.java:265)
at lucee.runtime.java.JavaObject.call(JavaObject.java:287)
at lucee.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:787)
at lucee.runtime.PageContextImpl.getFunction(PageContextImpl.java:1998)
at print_test.luceejavaxprinttest_cfm$cf.call(/print_test/LuceeJavaxPrintTest.cfm:5)
at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:1028)
at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:951)
at lucee.runtime.listener.ClassicAppListener._onRequest(ClassicAppListener.java:65)
at lucee.runtime.listener.MixedAppListener.onRequest(MixedAppListener.java:45)
at lucee.runtime.PageContextImpl.execute(PageContextImpl.java:2715)
at lucee.runtime.PageContextImpl._execute(PageContextImpl.java:2701)
at lucee.runtime.PageContextImpl.executeCFML(PageContextImpl.java:2672)
at lucee.runtime.engine.Request.exe(Request.java:45)
at lucee.runtime.engine.CFMLEngineImpl._service(CFMLEngineImpl.java:1259)
at lucee.runtime.engine.CFMLEngineImpl.serviceCFML(CFMLEngineImpl.java:1205)
at lucee.loader.engine.CFMLEngineWrapper.serviceCFML(CFMLEngineWrapper.java:97)
at lucee.loader.servlet.CFMLServlet.service(CFMLServlet.java:51)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.ajp.AjpProcessor.service(AjpProcessor.java:432)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: javax/print/attribute/standard/Fidelity
... 45 more
The code runs fine within Eclipse, and returns a list of installed printers, as well as a list of media types available on a specific printer within our environment.
Here is the custom tag code for <cf_print>:
(c:\lucee\tomcat\lucee-server\context\customtags\cf_print.cfm)
<cfparam name="attributes.printer">
<cfparam name="attributes.source">
<cfparam name="attributes.attributeStruct">
<cfparam name="attributes.pages">
<cfscript>
CreateObject("java", "com.cigcustom.lucee.CFPrint03_CIG").printFile(attributes.printer, attributes.source, attributes.attributeStruct, attributes.pages);
</cfscript>
(c:\inetpub\wwwroot\print_test\LuceePrintWorld3.cfm)
<cfset plain_printer_settings=StructNew()>
<cfset plain_printer_settings["mediatype"] = "Plain">
<cfset plain_printer_settings["pagescaling"] = "none">
<cf_print printer="HP LaserJet 600 M601 M602 M603 PCL6" source="c:\temp\Multipage_Test.pdf" attributeStruct="#plain_printer_settings#" pages="1">
That returns a similar error, but in this case on javax.print.attribute.standard.Media
Lucee 6.0.1.83 Error (java.lang.NoClassDefFoundError)
Message javax/print/attribute/standard/Media
Stacktrace The Error Occurred in
/print.cfm: line 9
called from C:\inetpub\wwwroot\print_test\LuceePrintWorld3.cfm: line 5
Java Stacktrace lucee.runtime.exp.NativeException: javax/print/attribute/standard/Media
at com.cigcustom.lucee.CFPrint03_CIG.findSupportedMedia(CFPrint03_CIG.java:274)
at com.cigcustom.lucee.CFPrint03_CIG.handlePrintAttributes(CFPrint03_CIG.java:151)
at com.cigcustom.lucee.CFPrint03_CIG.printFile(CFPrint03_CIG.java:93)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at lucee.runtime.reflection.pairs.MethodInstance.invoke(MethodInstance.java:56)
at lucee.runtime.java.JavaObject.call(JavaObject.java:265)
at lucee.runtime.java.JavaObject.call(JavaObject.java:287)
at lucee.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:787)
at lucee.runtime.PageContextImpl.getFunction(PageContextImpl.java:1998)
at print_cfm$cf.call(/print.cfm:9)
at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:1028)
at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:951)
at lucee.runtime.PageContextImpl.doInclude(PageContextImpl.java:943)
at lucee.runtime.tag.CFTag.doInclude(CFTag.java:319)
at lucee.runtime.tag.CFTag.cfmlStartTag(CFTag.java:245)
at lucee.runtime.tag.CFTag.doStartTag(CFTag.java:179)
at print_test.luceeprintworld3_cfm$cf.call(/print_test/LuceePrintWorld3.cfm:5)
at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:1028)
at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:951)
at lucee.runtime.listener.ClassicAppListener._onRequest(ClassicAppListener.java:65)
at lucee.runtime.listener.MixedAppListener.onRequest(MixedAppListener.java:45)
at lucee.runtime.PageContextImpl.execute(PageContextImpl.java:2715)
at lucee.runtime.PageContextImpl._execute(PageContextImpl.java:2701)
at lucee.runtime.PageContextImpl.executeCFML(PageContextImpl.java:2672)
at lucee.runtime.engine.Request.exe(Request.java:45)
at lucee.runtime.engine.CFMLEngineImpl._service(CFMLEngineImpl.java:1259)
at lucee.runtime.engine.CFMLEngineImpl.serviceCFML(CFMLEngineImpl.java:1205)
at lucee.loader.engine.CFMLEngineWrapper.serviceCFML(CFMLEngineWrapper.java:97)
at lucee.loader.servlet.CFMLServlet.service(CFMLServlet.java:51)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.ajp.AjpProcessor.service(AjpProcessor.java:432)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: javax/print/attribute/standard/Media
... 54 more
The code for that full version is considerably more complex (and probably out of the scope of this post).
Both are experiencing the same issue, however, on the same subset of native Java libraries, only when run within Lucee. This code also works perfectly when running from Eclipse, and earlier versions did work through Lucee, but stopped somewhere down the line.
If I create a very simple printing JAR that doesn’t call these javax.print.attribute.standard classes, I am still able to print through Lucee. Just without the settings customization we need.
As far as compile, for the test program, I’m just exporting a JAR through Eclipse’s context menu. Only “Export generated class files and resources” is checked. No compression etc.
The JAR for the full program is getting exported as a Maven project, as it uses PDFBox. At first, I was trying to do this without Maven by putting the PDFBox libraries in our Lucee lib folder (c:\lucee\tomcat\lucee-server\context\lib) along with the program JAR, but I ran into struggles with that. Via Maven, I was able to combine PDFBox (as well as a req’d Log4j library) and my program into a fat JAR, which allowed the PDFBox calls to work within Lucee.