运行servlet时出现'Batik not in classpath'错误

时间:2011-10-25 14:55:34

标签: java servlets classpath

我正在编写Apache FOP中包含的FopServlet.java的扩展。

我的平台是Linux CentOS 5.7-64bit,带有Tomcat 5.5。

servlet'有效',但我无法处理SVG文件。

Tomcat运行servlet时遇到的错误是

  

'蜡染不在课堂上'。

但在'webapps/fop/WEB-INF/lib'中有'batik-all-1.7.jar'和所有其他广告。

我不是Java专家,所以我无法专注于这个问题;谷歌搜索,也许有一个丢失的罐子,但哪一个?

AVVERTENZA: Batik not in class path
java.lang.NoClassDefFoundError: org/w3c/dom/svg/SVGDocument
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1862)
        at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:888)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1341)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1220)
        at org.apache.batik.dom.svg.SVGDOMImplementation.createDocument(Unknown Source)
        at org.apache.batik.dom.util.SAXDocumentFactory.startElement(Unknown Source)
        at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
        at org.apache.xerces.impl.dtd.XMLDTDValidator.startElement(Unknown Source)
        at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
        at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)
        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
        at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
        at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
        at org.apache.batik.dom.util.SAXDocumentFactory.createDocument(Unknown Source)
        at org.apache.batik.dom.util.SAXDocumentFactory.createDocument(Unknown Source)
        at org.apache.batik.dom.svg.SAXSVGDocumentFactory.createDocument(Unknown Source)
        at org.apache.batik.dom.svg.SAXSVGDocumentFactory.createSVGDocument(Unknown Source)
        at org.apache.fop.image.loader.batik.PreloaderSVG$Loader.getImage(PreloaderSVG.java:122)
        at org.apache.fop.image.loader.batik.PreloaderSVG$Loader.access$100(PreloaderSVG.java:105)
        at org.apache.fop.image.loader.batik.PreloaderSVG.preloadImage(PreloaderSVG.java:73)
        at org.apache.xmlgraphics.image.loader.ImageManager.preloadImage(ImageManager.java:175)
        at org.apache.xmlgraphics.image.loader.cache.ImageCache.needImageInfo(ImageCache.java:128)
        at org.apache.xmlgraphics.image.loader.ImageManager.getImageInfo(ImageManager.java:122)
        at org.apache.fop.fo.flow.ExternalGraphic.bind(ExternalGraphic.java:81)
        at org.apache.fop.fo.FObj.processNode(FObj.java:123)
        at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.startElement(FOTreeBuilder.java:282)
        at org.apache.fop.fo.FOTreeBuilder.startElement(FOTreeBuilder.java:171)
        at org.apache.xalan.transformer.TransformerIdentityImpl.startElement(TransformerIdentityImpl.java:1072)
        at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
        at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source)
        at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
        at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
        at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:484)
        at org.apache.fop.servlet.FopServlet.render(FopServlet.java:260)
        at org.apache.fop.servlet.FopServlet.renderFO(FopServlet.java:199)
        at org.apache.fop.servlet.FopServlet.doGet(FopServlet.java:136)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
        at java.lang.Thread.run(Thread.java:636)
Caused by: java.lang.ClassNotFoundException: org.w3c.dom.svg.SVGDocument
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1374)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1220)
        ... 64 more

3 个答案:

答案 0 :(得分:19)

它似乎是bug in Fop,他们忘了包含依赖项。

缺少的类位于JAR文件中 - xml-apis-ext.jar也可以从Apache xml-commons project获取。

答案 1 :(得分:5)

错误消息具有误导性,这实际上是缺少外部的xml commons。

答案 2 :(得分:0)

如果你使用.jar文件从fedora执行Batik,由于java忽略-classpath标志,这是非常痛苦的。 我假设在/ usr / share / java中有蜡染 根据您的系统选择位置 一种解决方案可能如下: 创建一个临时目录(我假设你是超级用户,无论如何你总是可以sudo命令)

# mkdir scratch
# cd scratch
# jar -xf /usr/share/java/batik-rasterizer.jar

这将jar文件的内容输出到临时,然后创建一个MANIFEST.MF文件或从转储中获取输出

#cp META-INF/MANIFEST.MF .

现在编辑MANIFEST.MF文件(我喜欢使用vi,任何人都使用他们喜欢的文件)

#vi MANIFEST.MF

将一个Class-Path:行添加到MANIFEST.MF中,例如:

Class-Path: batik-all.jar xmlgraphics-commons.jar xml-commons-apis-ext.jar pdf-transcoder.jar avalon-framework.jar avalon-framework-api.jar apache-commons-logging.jar apache-commons-io.jar

然后关闭文件并重新创建jar文件

#jar cmf MANIFEST.MF /usr/share/java/batik-rasterizer.jar org/*

包含蜡染具有嵌套类的所有jar

然后你可以使用它!

$java -jar /usr/share/java/batik-rasterizer.jar -scriptSecurittyOff -m image/png -d image.png image.svg

例如

那就是!!!