【问题标题】:Confirming that jar files are being loaded确认 jar 文件正在加载
【发布时间】:2021-12-09 01:02:26
【问题描述】:

如何确认我的 JAR 文件已加载到 Coldfusion 中?我在 CF10 上。

我目前收到此错误:

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

我的网站结构如下:

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

在我的 application.cfc 中,我有以下代码:

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

这是我调用所有内容的代码:

<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>

更新 #1

我在管理员中查看并找到Settings Summary,其中列出了CF Server Java Class Path。我添加了 jar 文件的位置并重新启动了服务器。即使该路径存在于 Administrator 的类路径中,我仍然会遇到同样的错误。

更新 2

添加了缺少的属性“type”并得到以下错误:

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

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

完整的堆栈跟踪

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

更新 3

我的 application.cfc 中有这个

&lt;cfset This.javaSettings = {loadPaths: ["jar/"],loadColdFusionClassPath: false,reloadOnChange: true,watchInterval: 2}&gt;

我打电话给onApplicationStart() 仍然遇到同样的错误。

此时,我已删除 ColdFusion 类路径中的条目,它现在恢复为空的默认值。

我希望它能够在共享主机上使用javaSettings 变量加载 jar 文件。

【问题讨论】:

  • (编辑)嗯...刚刚注意到您忘记在 createObject 调用中包含对象“类型”。默认为“组件”。你需要告诉CF你想创建一个java类的实例:即createObject("java", "path.to.SomeClassName")。这就是错误所抱怨的。
  • @Leigh 添加了 type 属性,结果见更新#2。
  • 基本上这意味着加载新版本的 jar 时出现问题,因为类路径中已经有另一个版本。尝试将 loadColdFusionClassPath 设置为 false。请务必重新启动应用,以便应用新设置。
  • 您能否在“更新 2”中包含错误的完整堆栈跟踪?我们需要看到更多的异常,即“Caused by:”等。 (编辑)我看到一个线程提示缺少 jar,但是......这完全取决于跟踪中报告的原因。

标签: coldfusion


【解决方案1】:

更新:

(来自聊天的摘要)Batik 1.7 包含两个已与 CF 10 捆绑的 xml 解析库的较新版本。加载这两个版本将导致 ClassCastException

org.apache.xerces.jaxp.SAXParserFactoryImpl 不能转换为 javax.xml.parsers.SAXParserFactory

为避免该错误,请从batik-1.7/lib 目录中删除这两个 xml jar,以免加载它们:

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

另外,loadPaths 不是递归的。因此,如果子文件夹中包含任何 jar,则还必须包含这些子文件夹的路径。即

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

如果您对this.javaSettings 进行更改,请务必重新启动应用程序以确保应用更改。


找不到 ColdFusion 组件或接口

当您使用createObject 时,您需要包含对象“类型”。否则,它使用默认类型“组件”。这意味着 CF 正在使用您提供的路径(即“org.apache.batik.transcoder.image.PNGTranscoder”)搜索 component/cfc。由于您的应用程序可能不包含具有该路径的 cfc,这就是您收到上述错误消息的原因。

"java" 类型添加到您的所有createObject 调用中,它应该可以工作:

createObject("java", "org.apache.batik.transcoder.image.PNGTranscoder").init();

【讨论】:

  • 感谢您发现我的不一致之处...这样做了,得到了一个新错误。请参阅更新 #2。
  • FWIW,我将我的代码上传到我的共享主机上,它开箱即用,无需移动文件或重新启动服务(无论如何这永远不会发生)。我将寻找解释为什么 this.javaSettings 在我的开发环境中不起作用....再次感谢您的帮助
  • 说实话,这和我在本地尝试时的体验比较一致。我所做的只是提取罐子,将子目录 lib/ 添加到路径中,然后更改 Application.cfc 名称以确保我从零开始。我知道您提到您重新启动了应用程序,但是..也许您之前的测试中的某些东西仍然在搞砸?至少从this.javaSettings的角度来看。
  • 是的,当您不关心任何应用程序/会话被丢弃时,它非常适合快速开发测试。对于生产来说不是那么多;-)
【解决方案2】:

我们遇到了类似的问题,即类路径的顺序导致了 CF2021 中的问题。我首先包含了一个 jar 文件,但应该在加载所有主库后稍后完成。因此,根据我的经验,意识到将新 jars 添加到类路径时,始终添加到最后。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 2011-05-31
    • 2011-04-07
    • 1970-01-01
    相关资源
    最近更新 更多