我使用mojohausjaxb2-maven-plugin从xsd模式文件中生成Java源。我的pom.xml看起来是这样的:
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.5.0</version>
<executions>
<execution>
<id>xjc-1</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<packageName>my.first.package.types</packageName>
<sources>
<source>src/main/java/META-INF/wsdl/firstSchema.xsd</source>
</sources>
</configuration>
</execution>
<execution>
<id>xjc-2</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<packageName>my.second.package.types</packageName>
<sources>
<source>src/main/java/META-INF/wsdl/secondSchema.xsd</source>
</sources>
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
</executions>
<configuration>
<outputDirectory>src/main/javagen</outputDirectory>
</configuration>
</plugin>这个插件配置应该与找到的插件这里相对应。当我运行构建时,从第一个模式生成的源文件是,也是放在第二个包中的。有人能解释一下为什么会这样吗?那是窃听器还是我漏掉了什么?
非常感谢您的任何投入!
编辑:
我也尝试了maven-jaxb2插件。同样的结果!所以这似乎是一个通用的问题。我的maven-jaxb2-plugin插件配置如下:
...
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.14.0</version>
<executions>
<execution>
<id>first</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaIncludes>
<include>firstSchema.xsd</include>
</schemaIncludes>
<generatePackage>my.first.package.types</generatePackage>
</configuration>
</execution>
<execution>
<id>second</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaIncludes>
<include>secondSchema.xsd</include>
</schemaIncludes>
<generatePackage>my.second.package.types</generatePackage>
</configuration>
</execution>
</executions>
<configuration>
<schemaDirectory>src/main/java/META-INF/wsdl</schemaDirectory>
<generateDirectory>src/main/javagen</generateDirectory>
</configuration>
</plugin>有人有什么想法吗?这开始让我有点恼火..。
编辑:
我发现这与一些xsd文件导入的文件有关,如下所示:
<xs:import namespace="http://referenced/namespace"
schemaLocation="referencedSchema.xsd" />在我看来,Maven似乎忽略了名称空间标记。我怎么能告诉Maven别再这么做了?
发布于 2020-11-13 12:09:55
我可以在很久很久以前回答我自己的问题。问题是,我们还使用maven jaxws插件从wsdl文件生成web服务。这两个插件实际上都使用底层的xsf文件,并将数据结构类生成到相应的包中。因此,解决方案是从pom中删除jaxb插件。所有xsd只生成一次。
https://stackoverflow.com/questions/58181026
复制相似问题