2

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.

Delimitry
  • 2,987
  • 4
  • 30
  • 39
coder1608
  • 171
  • 6
  • 14

1 Answers1

2

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.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • I wanted to maintain my schemas in different folders and apply different xsdConfig files. How Can I do it ? – coder1608 Jun 02 '15 at 10:07
  • Please ask this as a new question on Stack Overflow. Create separate folders for each set of schemas and give each one its own `xsdconfig` file. – Tim Biegeleisen Jun 02 '15 at 10:13
  • Created a new question.you could find it here http://stackoverflow.com/questions/30593974/xmlbeans-i-wanted-to-maintain-my-schemas-in-different-folders-and-apply-differ – coder1608 Jun 02 '15 at 10:50
  • where we should give the xsdconfig files ? inside the individual folder or separate folder ? if no tragetName space available .. how can I build the schema into specified package name ? – coder1608 Jun 02 '15 at 11:22