javamaven-2jaxb2schemagenjaxb2-maven-plugin

Can I include java source from multiple projects when running schemagen using the jaxb2-maven-plugin?


I have a multi module maven project and I need to build an XML schema from JaxB annotated classes. These classes are in different maven projects. Can I use the jaxb2-maven-plugin to generate a single schema by pointing at the source from all of the projects? Perhaps like this ...

<configuration>
    ...
    <includes>    
        <include>../OtherProj1/src/main/java/**/*.java</include>
        <include>../OtherProj2/src/main/java/**/*.java</include>
        <include>**/*.java</include>
    </includes>
    ...
</configuration>

Or do I need to create a schema for each project individually and then import them into a parent schema instead?

I am using maven 2.2.1 and jaxb2-maven-plugin 1.3.


Solution

  • I think the antrun plugin is the only way to include sources from outside of the mvn project for generating the XML schema.

    <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.6</version>
        <executions>
            <execution>
                <phase>generate-resources</phase>
                <configuration>
                    <target>                        
                        <taskdef name="schemagen" classname="com.sun.tools.jxc.SchemaGenTask">
                        </taskdef>
                        <schemagen destdir="src/main/resources/" includes="<comma separated paths to include>"
                            excludes="<comma separated paths to exclude>">
                            <src path="src/main/java" />
                            <src path="../OtherProj1/src/main/java" />
                            <src path="../OtherProj2/src/main/java" />                  
                        </schemagen>
                        <move file="src/main/resources/schema1.xsd" tofile="src/main/resources/<filename>.xsd" />
                    </target>
                </configuration>
                <goals>
                    <goal>run</goal>
                </goals>
            </execution>
        </executions>
    </plugin>