[英]How to generate classes for XSD in Maven src/test, that reference XSD in src/main
The following maven setup: 以下maven设置:
src/main/resources/BaseTypes.xsd
src/test/resources/MyTypeUsingBaseTypes.xsd
Now I would like to have the BaseTypes generated into target/classes, while the MyTypeUsingBaseTypes into target/test-classes. 现在我想将BaseTypes生成到target / classes中,而MyTypeUsingBaseTypes生成target / test-classes。
The problem is, that the BaseTypes are also generated (= duplicated) into target/test-classes. 问题是,BaseTypes也会生成(=重复)到目标/测试类中。
I am using the org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.12.3, with two Executions: 我正在使用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>
Maybe something like this can do the job (check the paths) : 也许这样的事情可以完成这项工作(检查路径):
Try adding to your <configuration>
the following options : 尝试在
<configuration>
添加以下选项:
<schemaLanguage>
: Which tells what is the type of the file (wsdl, wadl, ear etc.) <schemaLanguage>
:它告诉文件的类型是什么(wsdl,wadl,ear等)
<schemaIncludes>
: This gives you the opportunity to select specific files <schemaIncludes>
:这使您有机会选择特定文件
<generatePackage>
: Will put the generated *.java files into package in the selected generation directory <generatePackage>
:将生成的* .java文件放入所选生成目录中的包中
That way you can write down as many as you want executions for as many as you want different schemas. 通过这种方式,您可以根据需要编写尽可能多的执行数据,以获得不同的模式。
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.