Maven - xmlbeans : working with multiple schema files to generate a single jar file

4.3k Views Asked by At

I have different service schema files(more than 5), from which I wanted to generate a jar file using xmlbeans.

I was using xmlbean plugin as follows

<plugins>
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>xmlbeans-maven-plugin</artifactId>
        <version>${xmlbeans.version}</version>
        <executions>
            <execution>
                <goals>
                    <goal>xmlbeans</goal>
                </goals>
                <phase>compile</phase>
            </execution>
        </executions>
        <inherited>true</inherited>
        <configuration>
            <download>true</download>
            <javaSource>${java.version}</javaSource>
            <schemaDirectory>src/main/xsd</schemaDirectory>
            <xmlConfigs>
                <xmlConfig implementation="java.io.File">src/main/xsdconfig/xsdconfig.xml</xmlConfig>
            </xmlConfigs>
        </configuration>
    </plugin>
</plugins>

I want to have different package name for different service schema. How to specify that and where to provide the schema path and xsdConfig file to apply the package details.

Please advice.

1

There are 1 best solutions below

4
Tim Biegeleisen On

You need to define a file ending in .xsdconfig (e.g. myConfig.xsdconfig) to map the targetNamespace in each of your schema files to a Java package name. Put this .xsdconfig file in the same directory as the corresponding .xsd file that you are compiling. Suppose for example you have the following .xsd file:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
       targetNamespace="http://your.company.org/dileep">
    ...
</xs:schema>

Then you would define the following myConfig.xsdconfig files as follows:

<!-- you must use the http://www.bea.com/2002/09/xbean/config namespace here -->
<xb:config xmlns:xb="http://www.bea.com/2002/09/xbean/config">
    <xb:namespace uri="http://your.company.org/dileep">   <!-- map this namespace -->
        <xb:package>org.company.your.dileep</xb:package>  <!-- to this Java package -->
    </xb:namespace>
    <!-- more namespace mappings can go here ... -->
</xb:config>

It is also possible to control the names of the Java classes generated from each of your schema files.

You can read more about this in the official XMLBeans documentation.