gpt4 book ai didi

java - 如何在 Maven src/test 中为 XSD 生成类,在 src/main 中引用 XSD

转载 作者:行者123 更新时间:2023-11-29 04:40:49 26 4
gpt4 key购买 nike

以下 Maven 设置:

src/main/resources/BaseTypes.xsd
src/test/resources/MyTypeUsingBaseTypes.xsd

现在我想将 BaseTypes 生成到目标/类中,而将 MyTypeUsingBaseTypes 生成到目标/测试类中。

问题是,BaseType 也会生成(= 重复)到目标/测试类中。

我正在使用 org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.12.3,有两个执行:

<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.12.3</version>
<executions>
<execution>
<id>gen-schemas</id>
<goals>
<goal>generate</goal>
</goals>
</execution>

<execution>
<id>gen-test-schemas</id>
<phase>generate-test-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<generateDirectory>target/generated-test-sources/xjc</generateDirectory>
<addTestCompileSourceRoot>true</addTestCompileSourceRoot>
<schemaDirectory>src/test/resources</schemaDirectory>
</configuration>
</execution>
</executions>
</plugin>

最佳答案

也许这样的事情可以完成这项工作(检查路径):

尝试添加到您的 <configuration>以下选项:

<schemaLanguage> : 这说明了文件的类型(wsdl、wadl、ear 等)

<schemaIncludes> : 这使您有机会选择特定文件

<generatePackage> : 将生成的*.java文件打包到选择的生成目录下

这样你就可以写下你想要的不同模式的执行次数。

<executions>
<execution>
<id>xjc-schema2</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaLanguage>wsdl</schemaLanguage>
<schemaDirectory>src/test/resources</schemaDirectory>
<schemaIncludes>
<include>MyTypeUsingBaseTypes.xsd</include>
</schemaIncludes>
<generatePackage>com.name.of.package.MyTypeUsingBaseTypes</generatePackage>

<generateDirectory>target/generated-test-sources/xjc</generateDirectory>
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
<execution>
<id>xjc-schema2v2</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaLanguage>wsdl</schemaLanguage>
<schemaDirectory>src/main/resources</schemaDirectory>
<schemaIncludes>
<include>BaseTypes.xsd</include>
</schemaIncludes>
<generatePackage>com.name.of.package.BaseTypes</generatePackage>

<generateDirectory>target/generated-sources/xjc</generateDirectory>
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
</executions>

关于java - 如何在 Maven src/test 中为 XSD 生成类,在 src/main 中引用 XSD,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39268205/

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