如何使用maven从外部jar文件中生成的xsd生成Schema Objects

时间:2011-09-20 20:31:09

标签: jaxb

我在src \ main \ resources文件夹结构下准备了一些xsd并创建了一个.jar文件现在我想在另一个应用程序中生成a.jar中的xsd的scheam对象,比如generateSource应用程序可以任何人帮我编写maven pom.xml文件中的插件 喜欢所有依赖项和插件所需的。

2 个答案:

答案 0 :(得分:1)

首先你需要使用像这样的maven-dependency-plugin来提取包含XSD的jar。

<plugin>
<!-- Unpack the jar into target directory -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.7</version>
<executions>
    <execution>
        <id>unpack</id>
        <phase>validate</phase>
        <goals>
            <goal>unpack-dependencies</goal>
        </goals>
        <configuration>
                            <outputDirectory>${unpack.directory}</outputDirectory>
            <overWriteIfNewer>true</overWriteIfNewer>
            <includeGroupIds>com.companyname</includeGroupIds>
            <includeArtifactIds>jarname</includeArtifactIds>
            <excludes>**/*.html,samples/**</excludes>
        </configuration>
    </execution>
</executions>

稍后您需要使用maven-jaxb2-plugin将提取的xsds转换为java类,如下所述。

<plugin>
<!-- Convert XSD to java classes using jaxb plugin -->
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.2</version>
<configuration>
    <extension>true</extension>
    <generateDirectory>${generated.source.directory}</generateDirectory>
</configuration>
<executions>
    <execution>
    <id>Generate java-from-schema</id>
    <goals>
        <goal>generate</goal>
    </goals>
    <configuration>
        <schemaDirectory>${unpack.directory}/XXX</schemaDirectory>
        <catalog>${unpack.directory}/catalog</catalog>
        <schemaIncludes>
            <schemaInclude>aaa/*.xsd</schemaInclude>
            <schemaInclude>bbb/*.xsd</schemaInclude>
            <schemaInclude>ccc/*.xsd</schemaInclude>
        </schemaIncludes>
    </configuration>
        </execution>
    </executions>

答案 1 :(得分:0)

请参阅separate schema compilation文档。