gpt4 book ai didi

java - XJC "Is not part of this compilation"问题

转载 作者:行者123 更新时间:2023-12-02 04:04:31 24 4
gpt4 key购买 nike

我正在使用 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 文件。

您必须配置xjbExcludeFiltersxjbSources 仅包含一个文件:

<xjbSources>
<xjbSource>src/main/xjb/xsd1.xjb</xjbSource>
</xjbSources>

关于java - XJC "Is not part of this compilation"问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34499299/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com