我正在使用Maven JAXB2插件从我的XSD生成Java类。
为此,我使用以下多个执行:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>xsd1</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<arguments>
<argument>-b</argument>
<argument>${basedir}/src/main/xjb/xsd1.xjb</argument>
</arguments>
<sources>
<source>${basedir}/src/main/xsd/xsd1.xsd</source>
</sources>
</configuration>
</execution>
<execution>
<id>xsd2</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<arguments>
<argument>-b</argument>
<argument>${basedir}/src/main/xjb/xsd2.xjb</argument>
</arguments>
<sources>
<source>${basedir}/src/main/xsd/xsd2.XSD</source>
</sources>
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
</executions>
</plugin>
我的XJB:
<jxb:bindings version="2.1" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
schemaLocation="../xsd/xsd1.xsd" node="/xsd:schema">
<jxb:schemaBindings>
<jxb:package name="com.example.xsd1" />
</jxb:schemaBindings>
<jxb:bindings node="//xsd:element[@name='Name']/xsd:complexType">
<jxb:class name="NameXsd1" />
</jxb:bindings>
</jxb:bindings>
<jxb:bindings version="2.1" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
schemaLocation="../xsd/xsd2.xsd" node="/xsd:schema">
<jxb:schemaBindings>
<jxb:package name="com.example.xsd2" />
</jxb:schemaBindings>
<jxb:bindings node="//xsd:element[@name='Name']/xsd:complexType">
<jxb:class name="NameXsd2" />
</jxb:bindings>
</jxb:bindings>
当我执行
mvn clean install
时,出现以下错误:[ERROR] file:/D:/Dev/myproject/src/main/xjb/xsd1.xjb [3,92]
com.sun.istack.SAXParseException2; systemId: file:/D:/Dev/myproject/src/main/xjb/xsd1.xjb; lineNumber: 3; columnNumber: 92; "file:/D:/Dev/myproject/src/main/xsd/xsd1.xsd" is not part of this compilation. Is it a mistake for "file:/D:/Dev/myproject/src/main/xsd/xsd2.xsd" ?
at com.sun.tools.xjc.reader.internalizer.Internalizer.reportError(Internalizer.java:624)
at com.sun.tools.xjc.reader.internalizer.Internalizer.reportError(Internalizer.java:618)
at com.sun.tools.xjc.reader.internalizer.Internalizer.buildTargetNodeMap(Internalizer.java:261)
at com.sun.tools.xjc.reader.internalizer.Internalizer.transform(Internalizer.java:146)
at com.sun.tools.xjc.reader.internalizer.Internalizer.transform(Internalizer.java:107)
at com.sun.tools.xjc.reader.internalizer.DOMForest.transform(DOMForest.java:439)
at com.sun.tools.xjc.ModelLoader.buildDOMForest(ModelLoader.java:345)
at com.sun.tools.xjc.ModelLoader.loadXMLSchema(ModelLoader.java:377)
at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:174)
at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:119)
at com.sun.tools.xjc.Driver.run(Driver.java:354)
at org.codehaus.mojo.jaxb2.javageneration.AbstractJavaGeneratorMojo.performExecution(AbstractJavaGeneratorMojo.java:402)
at org.codehaus.mojo.jaxb2.AbstractJaxbMojo.execute(AbstractJaxbMojo.java:257)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:133)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:108)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:76)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:116)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:361)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
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:497)
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)
任何的想法?
谢谢!
最佳答案
jaxb2-maven-plugin
考虑两个XJB文件。
您必须进行配置xjbExcludeFilters
或xjbSources
仅包含一个文件:
<xjbSources>
<xjbSource>src/main/xjb/xsd1.xjb</xjbSource>
</xjbSources>