使用XJC在Windows和Linux上区分XML目录中的相对路径

时间:2014-11-10 13:59:31

标签: jaxb xjc

我们在JDK 6"中使用XJC版本" JAXB 2.1.10; (通过使用jaxb2-maven-plugin)基于OGC的WFS 2.0生成JAXB类。 我们使用目录文件来解析WFS模式所依赖的模式。目录文件中的条目通过使用相对路径引用文件系统上的模式,例如

<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" prefer="system">

    <rewriteSystem
        systemIdStartString="http://www.w3.org/2001/"
        rewritePrefix="../../2001/"/>

    <rewriteSystem
        systemIdStartString="http://www.w3.org/1999/"
        rewritePrefix="../../w3c/"/>

    <rewriteSystem
        systemIdStartString="http://schemas.opengis.net/ows/1.1/"
        rewritePrefix="../../ows/1.1.0/"/>

    <rewriteSystem
        systemIdStartString="http://schemas.opengis.net/ows/1.1.0/"
        rewritePrefix="../../ows/1.1.0/"/>

    <rewriteSystem
        systemIdStartString="http://schemas.opengis.net/filter/2.0/"
        rewritePrefix="../../filter/2.0/"/>

</catalog>

这在linux上工作正常,但在Windows上,我们为目录中定义的每个文件获得 java.io.FileNotFoundException 。 XJC是由maven插件调用还是直接调用没有区别,行为是相同的。 实际上,我们并没有设法使用目录中的相对路径使XJC在Windows上工作。

运行mvn -X clean install的日志摘录:

+ Error stacktraces are turned on.
Apache Maven 2.2.1 (r801777; 2009-08-06 21:16:01+0200)
Java version: 1.6.0_20
Java home: C:\Program Files\Java\jdk1.6.0_20\jre
Default locale: de_DE, platform encoding: Cp1252
OS name: "windows 7" version: "6.1" arch: "amd64" Family: "windows"
[DEBUG] Configuring mojo 'org.codehaus.mojo:jaxb2-maven-plugin:1.5:xjc' -->
[DEBUG]   (f) bindingDirectory = C:\dev\depot\myproject\src\main\xsd\wfs\2.0
[DEBUG]   (f) catalog = C:\dev\depot\myproject\src\main\xsd\wfs\2.0\wfs.cat
[DEBUG]   (f) clearOutputDir = false
[DEBUG]   (f) dtd = false
[DEBUG]   (f) enableIntrospection = false
[DEBUG]   (f) encoding = UTF-8
[DEBUG]   (f) explicitAnnotation = false
[DEBUG]   (f) extension = false
[DEBUG]   (f) failOnNoSchemas = true
[DEBUG]   (f) npa = false
[DEBUG]   (f) nv = false
[DEBUG]   (f) outputDirectory = C:\dev\depot\myproject\target\generated-sources\jaxb
[DEBUG]   (f) project = MavenProject: com.myproject:MyProject:1.0.0-SNAPSHOT @ C:\dev\depot\myproject\pom.xml
[DEBUG]   (f) quiet = false
[DEBUG]   (f) readOnly = false
[DEBUG]   (f) relaxng = false
[DEBUG]   (f) relaxngCompact = false
[DEBUG]   (f) schemaDirectory = C:\dev\depot\myproject\src\main\xsd\wfs\2.0
[DEBUG]   (f) staleFile = C:\dev\depot\myproject\target\stale\wfs\2.0
[DEBUG]   (f) verbose = false
[DEBUG]   (f) wsdl = false
[DEBUG]   (f) xmlschema = true
[DEBUG] -- end configuration --
[INFO] [jaxb2:xjc {execution: wfs}]
[DEBUG] Using XJC of JAXB Reference Implementation  version 2.1.13
[DEBUG] The schema Directory is C:\dev\depot\myproject\src\main\xsd\wfs\2.0
[DEBUG] accept false for file C:\dev\depot\myproject\src\main\xsd\wfs\2.0\CVS
[DEBUG] accept false for file C:\dev\depot\myproject\src\main\xsd\wfs\2.0\wfs.cat
[DEBUG] accept false for file C:\dev\depot\myproject\src\main\xsd\wfs\2.0\wfs.xjb
[DEBUG] accept true for file C:\dev\depot\myproject\src\main\xsd\wfs\2.0\wfs.xsd
[DEBUG] The binding Directory is C:\dev\depot\myproject\src\main\xsd\wfs\2.0
[INFO] Generating source...
[DEBUG] C:\dev\depot\myproject\target\classes
[DEBUG] D:\mvnrep\commons-codec\commons-codec\1.3\commons-codec-1.3.jar
[DEBUG] D:\mvnrep\commons-lang\commons-lang\2.6\commons-lang-2.6.jar
[DEBUG] D:\mvnrep\org\apache\httpcomponents\httpclient\4.1.2\httpclient-4.1.2.jar
[DEBUG] D:\mvnrep\org\apache\httpcomponents\httpcore\4.1.2\httpcore-4.1.2.jar
[DEBUG] D:\mvnrep\commons-logging\commons-logging\1.1.1\commons-logging-1.1.1.jar
[DEBUG] The binding Directory is C:\dev\depot\myproject\src\main\xsd\wfs\2.0
[DEBUG] accept false for file C:\dev\depot\myproject\src\main\xsd\wfs\2.0\CVS
[DEBUG] accept false for file C:\dev\depot\myproject\src\main\xsd\wfs\2.0\wfs.cat
[DEBUG] accept false for file C:\dev\depot\myproject\src\main\xsd\wfs\2.0\wfs.xjb
[DEBUG] accept true for file C:\dev\depot\myproject\src\main\xsd\wfs\2.0\wfs.xsd
[DEBUG] JAXB XJC args: [-xmlschema, -catalog, C:\dev\depot\myproject\src\main\xsd\wfs\2.0\wfs.cat, -d, C:\dev\depot\myproject\target\generated-sources\jaxb, -classpath, C:\dev\depot\myproject\target\classes;D:\mvnrep\commons-codec\commons-codec\1.3\commons-codec-1.3.jar;D:\mvnrep\commons-lang\commons-lang\2.6\commons-lang-2.6.jar;D:\mvnrep\org\apache\httpcomponents\httpclient\4.1.2\httpclient-4.1.2.jar;D:\mvnrep\org\apache\httpcomponents\httpcore\4.1.2\httpcore-4.1.2.jar;D:\mvnrep\commons-logging\commons-logging\1.1.1\commons-logging-1.1.1.jar;, -b, C:\dev\depot\myproject\src\main\xsd\wfs\2.0\wfs.xjb, C:\dev\depot\myproject\src\main\xsd\wfs\2.0]
[INFO] parsing a schema...
[ERROR] null[-1,-1]
java.io.FileNotFoundException: C:\dev\depot\myproject\owsGetResourceByID.xsd (Das System kann die angegebene Datei nicht finden)
    at com.sun.tools.xjc.ErrorReceiver.error(ErrorReceiver.java:90)
    at com.sun.tools.xjc.reader.internalizer.DOMForest.parse(DOMForest.java:401)
    at com.sun.tools.xjc.reader.internalizer.DOMForest.parse(DOMForest.java:300)
    at com.sun.tools.xjc.reader.internalizer.AbstractReferenceFinderImpl.startElement(AbstractReferenceFinderImpl.java:95)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:501)
    at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:179)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:377)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2755)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
    at com.sun.tools.xjc.reader.internalizer.DOMForest.parse(DOMForest.java:393)
    at com.sun.tools.xjc.reader.internalizer.DOMForest.parse(DOMForest.java:300)
    at com.sun.tools.xjc.reader.internalizer.AbstractReferenceFinderImpl.startElement(AbstractReferenceFinderImpl.java:95)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:501)
    at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:179)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:377)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2755)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
    at com.sun.tools.xjc.reader.internalizer.DOMForest.parse(DOMForest.java:393)
    at com.sun.tools.xjc.reader.internalizer.DOMForest.parse(DOMForest.java:273)
    at com.sun.tools.xjc.ModelLoader.buildDOMForest(ModelLoader.java:321)
    at com.sun.tools.xjc.ModelLoader.loadXMLSchema(ModelLoader.java:374)
    at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:167)
    at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:113)
    at com.sun.tools.xjc.Driver.run(Driver.java:313)
    at org.codehaus.mojo.jaxb2.AbstractXjcMojo.execute(AbstractXjcMojo.java:327)
    at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
    at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
    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.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
    at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
    at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
    at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
...
[INFO] Failed to parse a schema.
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Could not process schema files in directory C:\dev\depot\myproject\src\main\xsd\wfs\2.0
[INFO] ------------------------------------------------------------------------
[DEBUG] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: Could not process schema files in directory C:\dev\depot\myproject\src\main\xsd\wfs\2.0
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:719)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
    at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
    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.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
    at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
    at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
    at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.MojoExecutionException: Could not process schema files in directory C:\dev\depot\myproject\src\main\xsd\wfs\2.0
    at org.codehaus.mojo.jaxb2.AbstractXjcMojo.execute(AbstractXjcMojo.java:343)
    at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
    ... 17 more
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Tue Nov 11 06:56:54 CET 2014
[INFO] Final Memory: 25M/181M
[INFO] ------------------------------------------------------------------------

有人遇到过类似的问题并能找到解决方案吗?

注意:
  - 使用绝对路径不是解决方案,因为我们希望它可以在Linux和Windows上工作   - 目前使用较新版本的XJC / JAXB不是一种选择   - 使用&#34; OGC模式和工具项目&#34;不是一个选项,因为我们想要完全控制生成过程,WFS模式的类只是自定义模式的类生成的副产品。为WFS生成类只是一个例子。

1 个答案:

答案 0 :(得分:1)

报告此类事件时,请始终发布mvn -X install。日志和堆栈跟踪告诉很多。例如,我的会从目录解析器中记录(以及其他)调试信息,因此您可以看到类似的内容:

resolveSystem(file:/C:/Projects/workspaces/mj2p/maven-jaxb2-plugin-project/tests/gh-issue-16/src/main/resources/ab/a.xsd)
resolveSystem(file:/C:/Projects/workspaces/mj2p/maven-jaxb2-plugin-project/tests/gh-issue-16/src/main/resources/ab/a.xsd)
resolveSystem(http://www.ab.org/b.xsd)
Resolved system: http://www.ab.org/b.xsd
    file:/C:/Projects/workspaces/mj2p/maven-jaxb2-plugin-project/tests/gh-issue-16/src/main/resources/ab/b.xsd
resolveSystem(http://www.ab.org/b.xsd)

我只是设置small test project来测试它,所以我可以确实确认目录中的相对路径是否正常工作。至少使用和JAXB 2.2.11。这是我使用的catalog file

REWRITE_SYSTEM "http://www.ab.org" "../ab"

重要说明:文件相对于目录文件本身已解析。我已将目录文件放在src/main/resources/ab/catalog.cat下,http://www.ab.org/b.xsd已解析为src/main/resources/ab/b.xsd

最后,您是否在GitHub上看到了ogc-schemas项目?它是我的旧OGC Schemas and Tools项目的延续,它使用JAXB XJC编译OGC Schemas。您需要的WFS架构是already compiled,您可以使用工件或使用提供的binding files自行编译。

顺便说一下,我如何在ogc-schemas项目中进行编译:

  

REWRITE_SYSTEM&#34; http://schemas.opengis.net&#34; &#34;行家:org.jvnet.ogc:OGC-模式:罐子:: / OGC&#34;

我认为您的问题是URL相对于目录文件是相对解析的,这可能不是您所期望的。

免责声明:我是上述ogc-schemas项目的作者。