user955615
user955615

Reputation: 1

How to generate the Schema Objectsfrom xsd present in external jar file using maven

I had prepared some xsd under src\main\resources folder structure and created a.jar file now I want to generate the scheam objects for xsd in a.jar in another application like generateSource application can anybody help me in writing the maven plugin in pom.xml file like what all dependencies and plugins required.

Upvotes: 0

Views: 1208

Answers (2)

Mahesh Babu
Mahesh Babu

Reputation: 19

1st you need to extract the jar which contains XSD using maven-dependency-plugin like this.

<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>

Later you need to use maven-jaxb2-plugin to convert extracted xsds to java classes as mentioned below.

<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>

Upvotes: 1

lexicore
lexicore

Reputation: 43651

Please see the separate schema compilation documentation.

Upvotes: 0

Related Questions