我有一些XSD,其中一些共享公共定义。我将这些通用定义分离到一个单独的XSD中。到目前为止,我通过跨项目的相对路径导入了这个common.xsd
。Thsi之所以起作用,是因为所有项目都在dame SCM存储库中。
现在,我将这些项目分离到单独的SCM存储库中,并且需要更改对common.xsd
的访问,而该访问已经存在于它自己的项目中(common-xml.jar
)。
我读到的是:http://www.sagehill.net/docbookxsl/writecatalog.html和https://github.com/highsource/maven-jaxb2-plugin/wiki/using-catalogs,但它不起作用,我也不起作用。不使用目录,xjc在maven-jaxb2-plugin/configuration/schemadirectory
中的路径configuret中查找common.xsd
。
即使添加maven-jaxb2-plugin/configuration/arg>-dxml.catalog.verbosity=999
(或者运行mvn-x-dxml.catalog.verbosity=999...
,它甚至不会通知读取目录文件。
当我使用XML表单并保留<!doctype..:>
元素时,我只获得目录文件的输出,但这会导致超时,因为代理仅允许浏览器连接到internet(公司策略)。
我也读到了这个答案maven-have一个XSD作为一个依赖项,但它会导致同样的问题:xjc在schema目录中查找要包含的文件,但我想避免将它提取到一个地方,在那里它可能会意外地签入SCM。
如何强制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 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"
<?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的纯文本目录或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)
有时仔细阅读就能解决问题...
https://github.com/highsource/maven-jaxb2-plugin/wiki/using-catalogs:
由于XJC中的bug,这只在未指定schemaLocation时才起作用。因此,不幸的是,下面的组合目前不起作用。
public“http://www.w3.org/1999/xlink”“w3c/1999/xlink.xsd”
从导入中删除schemaLocation
属性解决了这个问题。
问题内容: 我有几个重复使用相同实体的XSD。例如,无论是对的XSD 和都有一个在他们的标签来描述产品的问题。因此,我创建了一个文件来定义标记,并同时定义了 两个标记,并使用ProductQuoteRequest.xsdProduct.xsd`。 我想使用Castor从这些XSD生成Java类,并且让他们两个都使用相同的类来表示XSD,这样我就可以重用相同的逻辑将它们映射到模型的类。 Castor
问题内容: 我有一个巨大的QuickBooks SDK .XSD模式文件,该文件定义了我可以从QuickBooks发送/接收的XML请求/响应。 我希望能够轻松地从这些.XSD文件生成Java类,然后将其用于将XML编组为Java对象,以及将Java对象编组为XML。 是否有捷径可寻…? 理想情况下,它在运行时不需要基本Java发行版外部的任何库。但是我很灵活 问题答案: JAXB确实可以满足您的
我有两个XSD,其中一个包含另一个,让我们称它们为A和B。 B有很多xs:complexType定义,并且包含在a中,但是a只对其中的一些定义感兴趣。 现在发生的事情是为B中定义的所有类型生成类。我想要实现的是只为A直接引用的类型生成类。 我曾尝试修改XSD A以导入B,而不是包含,但对于maven jaxb插件来说,效果并不理想。 XSD A导入B: 生成源的插件设置: 我知道有一种方法可以从命
问题:“main.xsd”是一个有效的xml模式文档吗? 当使用解析器(或从python库(该库反过来使用xmllint)进行验证时,我会得到以下错误: 元素“{http://www.w3.org/2001/xmlschema}Element”,属性“ref”:不允许从该架构引用命名空间“http://imported”中的组件,因为没有由import语句指示。WXS架构main.xsd编译失败
与JAXB为给定XSD生成JAXB类类似,Jackson是否提供了从XSD或JSON生成Jackson类的实用程序。 JAXB类geberator已经生成了一组为XSD模式定义的类。例如,对于多态类型,JAXB具有以下注释,以基于XML元素名称来标识名称。 是否可以在杰克逊中创建类似的类。即,基于XML元素名称来标识类型。
有没有什么方法可以从wsdl生成xsd。任何链接或工具也可以。最简单的方法是什么?