Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confirming that jar files are being loaded

Tags:

coldfusion

How can I confirm that my JAR files have been loaded in Coldfusion? I'm on CF10.

I'm currently getting this error:

Could not find the ColdFusion component or interface org.apache.batik.transcoder.image.PNGTranscoder. 

My site structure goes as follow:

/root
/root/application.cfc
/root/jar/batik-1.7/

In my application.cfc, I have the following code:

<cfset This.javaSettings = {loadPaths: ["jar/"],loadColdFusionClassPath: true,reloadOnChange: true,watchInterval: 2}>

Here is my code in terms of calling everything:

<cffunction name="getPng" access="public" output="true">        
    <cfsavecontent variable="out">
    <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
    <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
         width="612px" height="792px" viewBox="0 0 612 792" enable-background="new 0 0 612 792" xml:space="preserve">
    <path fill="##006838" stroke="##414042" stroke-miterlimit="10" d="M416.413,388.223c0,6.627-5.373,12-12,12H140.317
        c-6.627,0-12-5.373-12-12V272.54c0-6.627,5.373-12,12-12h264.096c6.627,0,12,5.373,12,12V388.223z"/>
    <text id="HomeScore" transform="matrix(1 0 0 1 358.5391 361.333)" fill="##F1F2F2" font-family="'ArialMT'" font-size="24">3</text>
    <text id="Home" transform="matrix(1 0 0 1 155.3018 361.333)" fill="##F1F2F2" font-family="'ArialMT'" font-size="24">TEAM B</text>
    <text id="VisitorScore" transform="matrix(1 0 0 1 358.5391 301.8096)" fill="##F1F2F2" font-family="'ArialMT'" font-size="24">2</text>
    <text id="Visitor" transform="matrix(1 0 0 1 155.3018 301.8096)" fill="##F1F2F2" font-family="'ArialMT'" font-size="24">TEAM A</text>
    </svg>
    </cfsavecontent>

    <cfreturn out>
</cffunction>

<cffunction name="renderPng" access="public" output="false">
    <cfscript>

        /*http://cfsearching.blogspot.ca/2008/02/cool-text-effects-with-svg-and-batik.html*/
        pngPath = "test.png";
        pngFile = expandPath(pngPath);

        transcoder = createObject("java", "org.apache.batik.transcoder.image.PNGTranscoder").init();
        inputStream = createObject("java", "java.io.StringBufferInputStream").init(getPng());
        input = createObject("java", "org.apache.batik.transcoder.TranscoderInput").init(inputStream);
        outputStream = createObject("java", "java.io.FileOutputStream").init(ExpandPath(pngFile));
        output = createObject("java", "org.apache.batik.transcoder.TranscoderOutput").init(outputStream);
        transcoder.transcode(input, output);
        outputStream.close();

        return pngFile;
    </cfscript>

</cffunction>

<cfscript>
    // CREATE OBJECT 
    obj = createObject("component", "#request.cfcPath#.utils");
    // CALL THE FUNCTION
    png = obj.renderPng();
</cfscript>

Update #1

I was checking in the administor and found Settings Summary, which listed CF Server Java Class Path. I added the location of my jar files and rebooted the server. Even though the path is present in the class path in the Administrator, I still get that same error.

Update 2

Added the missing attribute "type" and getting the following error:

java.lang.NoClassDefFoundError: org/apache/batik/dom/util/DocumentFactory

Line 554: transcoder = createObject("java", "org.apache.batik.transcoder.image.PNGTranscoder").init();

Full stack trace

java.lang.ClassNotFoundException: org.apache.batik.dom.util.DocumentFactory at coldfusion.bootstrap.BootstrapClassLoader.loadClass(BootstrapClassLoader.java:235) at java.lang.ClassLoader.loadClass(ClassLoader.java:356) at java.lang.Class.getDeclaredFields0(Native Method) at java.lang.Class.privateGetDeclaredFields(Class.java:2317) at java.lang.Class.privateGetPublicFields(Class.java:2350) at java.lang.Class.getFields(Class.java:1378) at coldfusion.runtime.java.ObjectHandler.Initialize(ObjectHandler.java:35) at coldfusion.runtime.java.ObjectHandler.(ObjectHandler.java:30) at coldfusion.runtime.java.ReflectionCache.get(ReflectionCache.java:38) at coldfusion.runtime.java.JavaProxy.(JavaProxy.java:35) at coldfusion.runtime.java.JavaProxyFactory.getProxy(JavaProxyFactory.java:117) at coldfusion.runtime.ProxyFactory.getProxy(ProxyFactory.java:65) at coldfusion.runtime.CFPage.createObjectProxy(CFPage.java:5747) at coldfusion.runtime.CFPage.CreateObject(CFPage.java:5710) at coldfusion.runtime.CFPage.CreateObject(CFPage.java:5644) at coldfusion.runtime.CFPage.CreateObject(CFPage.java:5619) at coldfusion.runtime.CFPage.CreateObject(CFPage.java:5566) at cfutils2ecfc521921384$funcRENDERPNG.runFunction(C:\websites\mgs_bootstrap\basic\cfc\utils.cfc:554) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:472) at coldfusion.filter.SilentFilter.invoke(SilentFilter.java:47) at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:368) at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:55) at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:321) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:220) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:655) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:444) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:414) at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2432) at cfsvgtest2ecfm1573707502.runPage(C:\websites\mgs_bootstrap\svgtest.cfm:5) at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:244) at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:444) at coldfusion.runtime.CfJspPage._emptyTcfTag(CfJspPage.java:2799) at cfapplication2ecfc733577694$funcONREQUEST.runFunction(C:\websites\mgs_bootstrap\application.cfc:87) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:472) at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:368) at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:55) at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:321) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:220) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:655) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:444) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:414) at coldfusion.runtime.AppEventInvoker.invoke(AppEventInvoker.java:108) at coldfusion.runtime.AppEventInvoker.onRequest(AppEventInvoker.java:300) at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:418) at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48) at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40) at coldfusion.filter.PathFilter.invoke(PathFilter.java:112) at coldfusion.filter.LicenseFilter.invoke(LicenseFilter.java:30) at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:94) at coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:79) at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28) at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38) at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46) at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38) at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22) at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:62) at coldfusion.CfmServlet.service(CfmServlet.java:204) at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42) at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:414) at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:203) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:298) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:722)

Update 3

I have this in my application.cfc

<cfset This.javaSettings = {loadPaths: ["jar/"],loadColdFusionClassPath: false,reloadOnChange: true,watchInterval: 2}>

I called onApplicationStart() and still getting that same error.

At this point, I have removed my entry in the ColdFusion Class Path and it's now back to the default value which is empty.

I want it to work loading the jar files using the javaSettings variable as I'm on shared hosting.

like image 723
TechFanDan Avatar asked Aug 06 '14 14:08

TechFanDan


People also ask

What is jar verification?

Typically, verification of signed JAR files will be the responsibility of your JavaTM runtime environment. Your browser will verify signed applets that it downloads. Signed applications invoked with the -jar option of the interpreter will be verified by the runtime environment.

How do I make sure a JAR file open in Java?

Right-click on the JAR file. Go to “Open With Other Applications”. Select Show other applications. Select Open With OpenJDK Java X Runtime.


1 Answers

Update:

(Summary from chat) Batik 1.7 includes newer versions of two xml parsing libraries that are already bundled with CF 10. Loading both versions will cause a ClassCastException

org.apache.xerces.jaxp.SAXParserFactoryImpl cannot be cast to javax.xml.parsers.SAXParserFactory

To avoid that error, remove these two xml jars from the batik-1.7/lib directory so they are not loaded:

  /batik-1.7/lib/xerces_2_5_0.jar
  /batik-1.7/lib/xml-apis.jar

Also, loadPaths is not recursive. So if there are any jars contained in subfolders, you must include the path of those subfolders as well. ie

   This.javaSettings = {loadPaths: ["/jar/batik-1.7","/jar/batik-1.7/lib"]};

If you make changes to the this.javaSettings, be sure to restart the application to ensure the changes are applied.


Could not find the ColdFusion component or interface

When you use createObject, you need to include the object "type". Otherwise, it uses the default type "component". Meaning CF is searching for a component/cfc with the path you supplied ie "org.apache.batik.transcoder.image.PNGTranscoder". Since your application probably does not contain a cfc with that path, that is why you are getting the error message above.

Add type "java" to all of your createObject calls and it should work:

createObject("java", "org.apache.batik.transcoder.image.PNGTranscoder").init();
like image 115
Leigh Avatar answered Nov 21 '22 01:11

Leigh