Generating XSD schemas from JAXB types in Maven?

前端 未结 2 1391
天涯浪人
天涯浪人 2020-12-16 15:12

I\'m trying to basically generate XSD schemas from my model classes annotated in JAXB using a Maven plugin. Here\'s the relevant code in my POM:



        
相关标签:
2条回答
  • 2020-12-16 15:41

    Here's the win:

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>jaxb2-maven-plugin</artifactId>
        <version>1.3.1</version>
        <executions>
            <execution>
                <goals>
                    <goal>schemagen</goal>
                </goals>
                <phase>generate-resources</phase>
                <configuration>
                    <includes>
                        <include>com/myproject/model/*.java</include>
                    </includes>
                    <outputDirectory>${project.build.directory}/schemas</outputDirectory>
                </configuration>
            </execution>
        </executions>
    </plugin>
    
    0 讨论(0)
  • 2020-12-16 15:49

    Improving on Naftuli Tzvi Kay's answer, I found it more convenient to use the now-current version 2.2 of the jaxb2-maven-plugin, like in this sample (as the 2.x version requires slightly different configuration):

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>jaxb2-maven-plugin</artifactId>
        <version>2.2</version>
        <executions>
            <execution>
                <goals>
                    <goal>schemagen</goal>
                </goals>
                <phase>generate-resources</phase>
                <configuration>
                    <sources>
                        <source>src/main/java/com/foo/model/xml</source>
                    </sources>
                    <outputDirectory>${project.build.directory}/schemas</outputDirectory>
                </configuration>
            </execution>
        </executions>
    </plugin>
    

    See the plugin documentation for more details.

    0 讨论(0)
提交回复
热议问题