5

I have a problem with maven-jaxb2-plugin . What I am trying to achieve is to generate-sources from x different wsdl's into different packages.

I would like to avoid method with multiple <execution> so I could leave pom.xml untouched when I add another wsdl.

I configured maven plugin like this:

<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <version>0.12.1</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                    <schemaLanguage>WSDL</schemaLanguage>
                    <schemaDirectory>src/main/resources/webservice/wsdl</schemaDirectory>
                    <schemaIncludes>
                        <include>orig/*.wsdl</include>
                    </schemaIncludes>

                    <bindingDirectory>src/main/resources/webservice/xjb</bindingDirectory>
                    <bindingIncludes>
                        <include>orig/*.xjb</include>
                    </bindingIncludes>
            </configuration>
        </execution>
    </executions>
</plugin>

In my understanding, this way I specified .wsdl locations as well as binding files locations.

Now in a example binding file (all of them are constructed the same way) I got following code:

<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" 
    jaxb:version="2.1">


    <jaxb:bindings schemaLocation="../../wsdl/orig/soap1.wsdl"
        node="*/xs:schema">

        <jaxb:schemaBindings>
            <jaxb:package name="my.package.com.soap1" />
        </jaxb:schemaBindings>
    </jaxb:bindings>

</jaxb:bindings>

Another services are soap2, soap3 etc. all of them have similar binding files. If i understand this correct, thanks to that connfig i should be able to generate domain objects for my soap's each in separate package.

But when i run maven clean compile i got the following output:

[ERROR] Error while parsing schema(s).Location [ file:/C:/Users/me/workspace/orig-project/src/main/resources/webservice/wsdl/orig/soap1.wsdl{202,39}].
org.xml.sax.SAXParseException; systemId: file:/C:/Users/me/workspace/orig-project/src/main/resources/webservice/wsdl/orig/soap1.wsdl; lineNumber: 202; columnNumber: 39; 'Line' **is already defined**

What is more, for testing purposes I have tried configuring plugin to process each wsdl in separate <execution> (I want to avoid that in final code) and what i observed is that after first ex. soap1.wsdl was processed, the package was properly created but other soap.wsdl's packages wasn't created at all. (only first was processed).

What is wrong with that, and if it is possible to achieve what I want?

UPDATE: To clarify what I want to achieve I will post there solution that is working for me, but it forces me to edit POM every time I add new webservice:

<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <version>0.12.1</version>
    <executions>
        <execution>
            <id>soap1</id>
                <goals>
                    <goal>generate</goal>
                </goals>
                <configuration>

                    <schemaDirectory>src/main/resources/webservice/wsdl</schemaDirectory>
                    <schemaIncludes>
                        <include>Soap1.wsdl</include>
                    </schemaIncludes>
                    <generatePackage>my.package.com.soap1</generatePackage>
                </configuration>
        </execution>

        <execution>
            <id>soap2</id>
                <goals>
                    <goal>generate</goal>
                </goals>
            <configuration>
                <schemaDirectory>src/main/resources/webservice/wsdl</schemaDirectory>
                <schemaIncludes>
                    <include>Soap2.wsdl</include>
                </schemaIncludes>
                <generatePackage>my.package.com.soap2</generatePackage>
            </configuration>
        </execution>

        <execution>
            <id>soap3</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
            <schemaDirectory>src/main/resources/webservice/wsdl</schemaDirectory>
                <schemaIncludes>
                    <include>Soap3.wsdl</include>
                </schemaIncludes>
            <bindingDirectory>src/main/resources/webservice/xjb</bindingDirectory>
                <bindingIncludes>
                    <include>soap3.xjb</include>
                </bindingIncludes>
            <generatePackage>my.package.com.soap3</generatePackage>
            </configuration>
        </execution>
    </executions>
</plugin>

It looks like (maybe?) there is some problem with:

<jaxb:schemaBindings>
                <jaxb:package name="my.package.com.soap1" />
</jaxb:schemaBindings>

in my first (and wanted) solution. Any ideas?

funny-shmunny
  • 87
  • 1
  • 13
patrykos91
  • 3,506
  • 2
  • 24
  • 30

0 Answers0