简体   繁体   English

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

[英]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.

相关问题 如何将Src / Test / Resources文件夹指定为XSD资源路径 - How to Specify Src/Test/Resources folder as XSD resource path Maven布局:如何确保src / main不依赖于src / test? - Maven layout: How to be sure that src/main does not depend on src/test? 如何使用通用类从Xsd和Maven生成JAXB - How to generate JAXB from xsd with maven using common classes 如何防止 Maven 编译 src/test/java 中的类,这些类是在 generate-sources 阶段生成的? - How to prevent Maven from compiling classes in src/test/java, which are generated during the generate-sources phase? 是否可以从 src/main 中的 src/test 加载测试类? - Is it possible to load test classes from src/test in src/main? querydsl在src / main / java中生成Q类 - querydsl generate Q classes in src/main/java 如何从 src 文件夹调用测试类并使用 maven 构建 - How to call test classes from src folder and build using maven Maven项目中src / main / java和src / test / java之间的区别 - Difference between src/main/java and src/test/java in a Maven project 如何从包含其他XSD的XSD生成类 - How can I generate classes from XSD that includes another XSD 无法将 src/main/java 类导入 maven-spring-web 项目中的 src/test/java jUnit 测试。 IDE - 日食 - Cant import src/main/java classes into src/test/java jUnit tests in maven-spring-web project. IDE - Eclipse
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM