Mat*_*ias 5 java xjc maven maven-jaxb2-plugin jaxb2-maven-plugin
我正在使用 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>
Run Code Online (Sandbox Code Playgroud)
该插件配置应与此处找到的配置相对应。当我运行构建时,从第一个架构生成的源文件也被放入第二个包中。谁能向我解释为什么会这样?这是一个错误还是我错过了什么?
非常感谢您的任何意见!
编辑:
我也尝试了 maven-jaxb2-plugin 。结果一样!所以这似乎是一个一般的专家问题。我的 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>
Run Code Online (Sandbox Code Playgroud)
有人有什么想法吗?这开始让我有点恼火......
编辑:
我发现这与某些 xsd 文件导入了如下文件有关:
<xs:import namespace="http://referenced/namespace"
schemaLocation="referencedSchema.xsd" />
Run Code Online (Sandbox Code Playgroud)
在我看来,Maven 忽略了名称空间标签。我怎样才能告诉 Maven 停止这样做呢?
我可以回答我自己很久很久以前的问题。问题是我们还使用了 Maven jaxws 插件从 wsdl 文件生成 Web 服务。这两个插件实际上都采用底层 xsf 文件并生成数据结构类到各自的包中。所以解决办法就是把pom.xml中的jaxb插件去掉。所有 xsd 仅生成一次。
| 归档时间: |
|
| 查看次数: |
1034 次 |
| 最近记录: |