1

The following maven setup:

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.

The problem is, that the BaseTypes are also generated (= duplicated) into target/test-classes.

I am using the org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.12.3, with two Executions:

<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>
girafi
  • 131
  • 7

1 Answers1

3

Maybe something like this can do the job (check the paths) :

Try adding to your <configuration> the following options :

<schemaLanguage> : Which tells what is the type of the file (wsdl, wadl, ear etc.)

<schemaIncludes> : This gives you the opportunity to select specific files

<generatePackage> : Will put the generated *.java files into package in the selected generation directory

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>
Lazar Lazarov
  • 2,412
  • 4
  • 26
  • 35