1

我有一些 XSD,其中一些共享通用定义。我将这些通用定义分离到一个单独的 XSD 中。到目前为止,我common.xsd通过项目的相对路径导入了它。Thsi 之所以有效,是因为所有项目都在 dame SCM 存储库中进行。

现在我将项目分离到单独的 SCM 存储库中,并且我需要更改对common.xsd已经存在于其自己的项目中的访问 ( common-xml.jar)。

我读了 tis: http: //www.sagehill.net/docbookxsl/WriteCatalog.htmlhttps://github.com/highsource/maven-jaxb2-plugin/wiki/Using-Catalogs 但它对我不起作用。common.xsd该目录未使用,xjc在配置的路径中查找maven-jaxb2-plugin/configuration/schemaDirectory.

即使我添加 maven-jaxb2-plugin/configuration/arg>-Dxml.catalog.verbosity=999(或运行mvn -X -Dxml.catalog.verbosity=999 ...它甚至不会告诉读取目录文件。

当我使用 XML 表单并保留元素时,我只会获得目录文件的输出<!DOCTYPE ..:>,但这会导致超时,因为代理只允许浏览器连接到 Internet(公司策略)。

我还阅读了这个答案Maven - 将 XSD 作为依赖项,但它会导致相同的问题:xjc 在架构目录中查找要包含的文件,但我想避免将其提取到可能通过签入的位置单片机意外...

如何强制 xjc 查找要导入的 XSD 的位置?

这是我的 Maven 项目配置:

   <plugin>
      <groupId>org.jvnet.jaxb2.maven2</groupId>
      <artifactId>maven-jaxb2-plugin</artifactId>
      <version>0.14.0</version>
      <configuration>
        <args>-Dxml.catalog.verbosity=999</args>
        <clearOutputDir>true</clearOutputDir>
        <removeOldOutput>true</removeOldOutput>
        <specVersion>2.2</specVersion>
        <arguments>-Xcommons-lang</arguments>
        <schemaDirectory>../src/main/xsd</schemaDirectory>
        <catalogs>
          <catalog>
            <dependencyResource>
              <groupId>my.group.id</groupId>
              <artifactId>common-xml-definitions</artifactId>
              <resource>catalog.xml</resource> 
             <!-- alternatively 
              <resource>catalog.cat</resource>
             for plain text version -->;
            </dependencyResource>
          </catalog>
        </catalogs>
        <schemaIncludes>
          <schemaInclude>*.xsd</schemaInclude>
        </schemaIncludes>
        <bindingDirectory>../src/main/xjb</bindingDirectory>
        <bindingIncludes>
          <bindingInclude>bindings.xml</bindingInclude>
        </bindingIncludes>
        <schemaLanguage>XMLSCHEMA</schemaLanguage>
        <generatePackage>a.package.name</generatePackage>
        <verbose>false</verbose>
        <args>
          <arg>-XtoString</arg>
          <arg>-Xequals</arg>
          <arg>-XhashCode</arg>
        </args>
        <plugins>
          <plugin>
            <groupId>com.buschmais.jaxbfx</groupId>
            <artifactId>jaxbfx-plugin</artifactId>
            <version>1.1.0</version>
          </plugin>
          <plugin>
            <groupId>org.jvnet.jaxb2_commons</groupId>
            <artifactId>jaxb2-basics</artifactId>
            <version>0.12.0</version>
          </plugin>
        </plugins>
      </configuration>
    </plugin>

这是目录文件:

  • xml版本:

      <?xml version="1.0"?>
      <!DOCTYPE catalog
        PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN" "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd">
      <catalog
        xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"
        prefer="public">
        <rewriteSystem
          systemIdStartString="http://my.url/commonDefinitions"
          rewritePrefix="maven:my.package:common-xml-definitions:jar::!/xsd" />
      </catalog>
    
  • 纯文本版本:

    REWRITE_SYSTEM "http://my.url/commonDefinitions" "maven:my.package:common-xml-definitions:jar::!/xsd"
    

tagret XSD 的开头是:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:codef="http://my.url/commonDefinitions" xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
  jxb:version="1.0" elementFormDefault="qualified">
  <xs:import namespace="http://my.url/commonDefinitions"
    schemaLocation="commonDefinitions.xsd" />
 <!-- ... -->
</xs:schema>

带有 DOCTYPE 的 XML-Catalog 的 Maven 错误消息是:

[ERROR] Failed to execute goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.14.0:generate (MyProject generate-sources) on project MyProject: Error parsing catalog [jar:file:/d:/maven-repository/my/package/common-xml-definitions/1.0.0/common-xml-definitions-1.0.0.jar!/catalog.xml].: Connection timed out: connect -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.14.0:generate (MyProject generate-sources) on project MyProject: Error parsing catalog [jar:file:/d:/maven-repository/my/package/common-xml-definitions/1.0.0/common-xml-definitions-1.0.0.jar!/catalog.xml].
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Error parsing catalog [jar:file:/d:/maven-repository/my/package/common-xml-definitions/1.0.0/common-xml-definitions-1.0.0.jar!/catalog.xml].
    at org.jvnet.jaxb2.maven2.RawXJC2Mojo.parseResolvedCatalogURIs (RawXJC2Mojo.java:1205)
    at org.jvnet.jaxb2.maven2.RawXJC2Mojo.setupCatalogResolver (RawXJC2Mojo.java:876)
    at org.jvnet.jaxb2.maven2.RawXJC2Mojo.doExecute (RawXJC2Mojo.java:432)
    at org.jvnet.jaxb2.maven2.RawXJC2Mojo.execute (RawXJC2Mojo.java:320)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: java.net.ConnectException: Connection timed out: connect
    at java.net.DualStackPlainSocketImpl.connect0 (Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect (DualStackPlainSocketImpl.java:79)
    at java.net.AbstractPlainSocketImpl.doConnect (AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress (AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect (AbstractPlainSocketImpl.java:188)
    at java.net.PlainSocketImpl.connect (PlainSocketImpl.java:172)
    at java.net.SocksSocketImpl.connect (SocksSocketImpl.java:392)
    at java.net.Socket.connect (Socket.java:589)
    at java.net.Socket.connect (Socket.java:538)
    at sun.net.NetworkClient.doConnect (NetworkClient.java:180)
    at sun.net.www.http.HttpClient.openServer (HttpClient.java:463)
    at sun.net.www.http.HttpClient.openServer (HttpClient.java:558)

没有 DOCTYPE 的纯文本目录 ort XML 的错误消息:

[INFO] Parsing input schema(s)...
[DEBUG] Resolving publicId [http://my.url/commonDefinitions], systemId [commonDefinitions.xsd].
resolveSystem(commonDefinitions.xsd)
resolvePublic(http://my.url/commonDefinitions,commonDefinitions.xsd)
[DEBUG] Parent resolver has resolved publicId [http://my.url/commonDefinitions], systemId [commonDefinitions.xsd] to [null].
[DEBUG] SystemId [commonDefinitions.xsd] is not a Maven dependency resource URI. Returning parent resolver result [null].
[WARNING] Error while parsing schema(s).Location [ file:/D:/data/scm-workspace/MyProject/src/main/xsd/parad.xsd{6,46}].
org.xml.sax.SAXParseException: schema_reference.4: Schemadokument 'commonDefinitions.xsd' konnte nicht gelesen werden, da 1) das Dokument nicht gefunden werden konnte; 2) das Dokument nicht gelesen werden konnte; 3) das Root-Element des Dokuments nicht <xsd:schema> ist.
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException (ErrorHandlerWrapper.java:203)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.warning (ErrorHandlerWrapper.java:99)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError (XMLErrorReporter.java:392)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaErr (XSDHandler.java:4154)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaWarning (XSDHandler.java:4149)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.getSchemaDocument1 (XSDHandler.java:2491)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.getSchemaDocument (XSDHandler.java:2193)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.resolveSchema (XSDHandler.java:2084)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.constructTrees (XSDHandler.java:1014)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.parseSchema (XSDHandler.java:625)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadSchema (XMLSchemaLoader.java:610)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar (XMLSchemaLoader.java:569)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar (XMLSchemaLoader.java:535)
    at com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory.newSchema (XMLSchemaFactory.java:254)
    at com.sun.tools.xjc.reader.xmlschema.parser.SchemaConstraintChecker.check (SchemaConstraintChecker.java:111)
    at com.sun.tools.xjc.ModelLoader.loadXMLSchema (ModelLoader.java:342)
    at com.sun.tools.xjc.ModelLoader.load (ModelLoader.java:162)
    at com.sun.tools.xjc.ModelLoader.load (ModelLoader.java:117)
    at org.jvnet.mjiip.v_2_3.XJC23Mojo.loadModel (XJC23Mojo.java:50)
    at org.jvnet.mjiip.v_2_3.XJC23Mojo.doExecute (XJC23Mojo.java:40)
    at org.jvnet.mjiip.v_2_3.XJC23Mojo.doExecute (XJC23Mojo.java:28)
    at org.jvnet.jaxb2.maven2.RawXJC2Mojo.doExecute (RawXJC2Mojo.java:478)
    at org.jvnet.jaxb2.maven2.RawXJC2Mojo.execute (RawXJC2Mojo.java:320)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: java.io.FileNotFoundException: D:\data\scm-workspace\MyProject\src\main\xsd\commonDefinitions.xsd (Das System kann die angegebene Datei nicht finden)
    at java.io.FileInputStream.open0 (Native Method)
    at java.io.FileInputStream.open (FileInputStream.java:195)
    at java.io.FileInputStream.<init> (FileInputStream.java:138)
    at java.io.FileInputStream.<init> (FileInputStream.java:93)
    at sun.net.www.protocol.file.FileURLConnection.connect (FileURLConnection.java:90)
4

1 回答 1

2

有时仔细阅读可以解决问题...

https://github.com/highsource/maven-jaxb2-plugin/wiki/Using-Catalogs

由于 XJC 中的错误,这仅在未指定 schemaLocation时有效。因此,不幸的是,以下组合目前不起作用。

PUBLIC "http://www.w3.org/1999/xlink" "w3c/1999/xlink.xsd"
<import namespace="http://www.w3.org/1999/xlink" schemaLocation="http://www.w3.org/1999/xlink.xsd" />

从导入中删除schemaLocation属性解决了这个问题。

于 2019-09-19T05:50:13.850 回答