【发布时间】:2019-10-01 08:40:08
【问题描述】:
我正在使用 mojohaus jaxb2-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>
此插件配置应对应于找到的here。 当我运行构建时,从第一个模式生成的源文件也放入第二个包中。谁能向我解释为什么会这样?这是一个错误还是我错过了什么?
非常感谢您的任何意见!
编辑:
我也尝试了 maven-jaxb2-plugin。结果一样!所以这似乎是一个generell maven问题。我的 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 停止这样做?
【问题讨论】:
标签: java maven xjc maven-jaxb2-plugin jaxb2-maven-plugin