Ant无法找到XML目录解析程序

时间:2013-02-18 11:27:40

标签: ant apache-commons

我的Ant 1.8.2版本在响应SVG DTD请求时因W3C网站的HTTP 303响应而失败。所以我试图引入一个XML目录来在本地解决它们。

如果我没有改变类路径,我得到:

警告:找不到XML解析器;外部目录将被忽略

如果我将Apache XML Commons 1.2中的resolver.jar添加到类路径中(例如在ant调用中使用-lib),我得到

/ Users / mike /..../ build.xml:123:java.lang.reflect.InvocationTargetException     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)     在java.lang.reflect.Method.invoke(Method.java:597)     at org.apache.tools.ant.types.XMLCatalog $ ExternalResolver.processExternalCatalogs(XMLCatalog.java:1115)     在org.apache.tools.ant.types.XMLCatalog $ ExternalResolver.resolveEntity(XMLCatalog.java:960)     在org.apache.tools.ant.types.XMLCatalog.resolveEntity(XMLCatalog.java:391)

向我建议我找到了我正在使用的resolver.jar,但是没有Ant所期望的接口。

我应该在哪里获得与Ant一起使用的正确resolver.jar?

2 个答案:

答案 0 :(得分:2)

我找到了解决方案(好吧,解决方法......)

InvocationTargetException被证明是一个红色鲱鱼 - 次要错误。主要错误如下:我的目录文件catalog.xml包含对DTD catalog.dtd的相对引用,并且Ant(或解析程序)无法解析对catalog.dtd的引用。它查看包含我的构建文件的目录,而不是包含目录的目录。这显然是某个地方的错误;我怀疑,如果我进一步调查,那就是Ant将目录文件传递给目录解析器,没有基URI,或者基URI不正确,因此XML解析器必须猜测在哪里找到DTD,并猜测是错误的

我的解决方案是删除对DTD的引用。在此之后,目录中列出的URI已正确解析为本地副本。有趣的是,对本地副本的引用也与目录有关,因此目录解析器似乎知道目录的位置,但有人在解析时没有告诉Xerces。

答案 1 :(得分:0)

我有同样的问题,但对我来说,从Ant 1.8.1升级到1.9.4解决了这个问题。

我的猜测是根本原因是bug 52754

编辑:同样的问题以稍微不同的形式重新出现,使用JDK 1.6.0_18,堆栈跟踪如下:

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.tools.ant.types.XMLCatalog$ExternalResolver.processExternalCatalogs(XMLCatalog.java:1116)
    at org.apache.tools.ant.types.XMLCatalog$ExternalResolver.resolve(XMLCatalog.java:1007)
    at org.apache.tools.ant.types.XMLCatalog.resolve(XMLCatalog.java:420)
    at net.sf.saxon.style.XSLGeneralIncorporate.getIncludedStylesheet(XSLGeneralIncorporate.java:104)
    at net.sf.saxon.style.XSLStylesheet.spliceIncludes(XSLStylesheet.java:754)
    at net.sf.saxon.style.XSLStylesheet.preprocess(XSLStylesheet.java:676)
    at net.sf.saxon.PreparedStylesheet.setStylesheetDocument(PreparedStylesheet.java:331)
    at net.sf.saxon.PreparedStylesheet.prepare(PreparedStylesheet.java:163)
    at net.sf.saxon.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:139)
    at org.apache.tools.ant.taskdefs.optional.TraXLiaison.readTemplates(TraXLiaison.java:300)
    at org.apache.tools.ant.taskdefs.optional.TraXLiaison.createTransformer(TraXLiaison.java:317)
    at org.apache.tools.ant.taskdefs.optional.TraXLiaison.transform(TraXLiaison.java:178)
    at org.apache.tools.ant.taskdefs.XSLTProcess.process(XSLTProcess.java:842)
    at org.apache.tools.ant.taskdefs.XSLTProcess.execute(XSLTProcess.java:432)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:435)
    at org.apache.tools.ant.Target.performTasks(Target.java:456)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
    at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
    at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:441)
    at org.apache.tools.ant.taskdefs.CallTarget.execute(CallTarget.java:105)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:435)
    at org.apache.tools.ant.Target.performTasks(Target.java:456)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
    at org.apache.tools.ant.Main.runBuild(Main.java:851)
    at org.apache.tools.ant.Main.startAnt(Main.java:235)
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
    at java.lang.String.substring(String.java:1937)
    at java.lang.String.substring(String.java:1904)
    at org.apache.xml.resolver.helpers.PublicId.normalize(Unknown Source)
    at org.apache.xml.resolver.Catalog.addEntry(Unknown Source)
    at org.apache.tools.ant.types.resolver.ApacheCatalog.addEntry(ApacheCatalog.java:118)
    at org.apache.xml.resolver.readers.OASISXMLCatalogReader.startElement(Unknown Source)
    at org.apache.xml.resolver.readers.SAXCatalogReader.startElement(Unknown Source)
    at org.apache.xml.resolver.readers.SAXParserHandler.startElement(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.startElement(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.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
    at org.apache.xml.resolver.readers.SAXCatalogReader.readCatalog(Unknown Source)
    at org.apache.xml.resolver.Catalog.parseCatalogFile(Unknown Source)
    at org.apache.xml.resolver.Catalog.parsePendingCatalogs(Unknown Source)
    at org.apache.xml.resolver.Catalog.parseCatalog(Unknown Source)
    at org.apache.tools.ant.types.resolver.ApacheCatalogResolver.parseCatalog(ApacheCatalogResolver.java:118)
 ... 47 more

有趣的是,错误只发生在Windows上,而且只是零星发生,可能只有七次左右。

错误源自Apache Resolver库中PublicId类的normalize function

normal.indexOf(" ")有时会返回错误的值。例如,如果输入字符串为-//OASIS//ELEMENTS DITA 1.x Programming Domain//EN,则pos变量将获得50作为其值,即使公共ID字符串没有任何额外的空格。

这让我认为根本原因可能与JDK bug #6967156有某种关系,但我根本无法确定,因为在我们的案例中,错误是间歇性的,但错误报告中没有任何暗示这一点。