16

I'm creating a client with Maven2 that uses several web services. I'm restricted to using Axis2 or other framework supporting Apache HttpClient as an HTTP conduit because these services require integration with a managed certificate solution based on HttpClient.

I'm familiar with CXF's code-gen Maven plugin which allows multiple WSDLs to be input during code generation. However, the Axis2 code-gen plugin can process only one WSDL at a time.

How can I make Maven run wsdl2code for each WSDL during code-gen phase? Do I need multiple profiles for this?

The build section of POM looks like this:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-wsdl2code-maven-plugin</artifactId>
            <version>1.6.0</version>
            <executions>
                <execution>
                    <goals>
                        <goal>wsdl2code</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <unpackClasses>true</unpackClasses>
                <databindingName>adb</databindingName>
                <packageName>org.example.stackoverflow.axis2-maven</packageName>
                <!-- only one of these actually gets used by code generator -->
                <wsdlFile>src/main/resources/service1.wsdl</wsdlFile>
                <wsdlFile>src/main/resources/service2.wsdl</wsdlFile>
                <outputDirectory>target/generated-sources</outputDirectory>
                <syncMode>sync</syncMode>
            </configuration>
        </plugin>
    </plugins>
</build>

References

guido
  • 18,864
  • 6
  • 70
  • 95
David J. Liszewski
  • 10,959
  • 6
  • 44
  • 57

2 Answers2

24

You can try with this, i could not test it right now but i think should work

   <plugin>
        <groupId>org.apache.axis2</groupId>
        <artifactId>axis2-wsdl2code-maven-plugin</artifactId>
        <version>1.6.0</version>
        <executions>
            <execution>
                <id>ws1</id>
                <goals>
                    <goal>wsdl2code</goal>
                </goals>
                <configuration>
                   <unpackClasses>true</unpackClasses>
                   <databindingName>adb</databindingName>
                   <packageName>org.example.stackoverflow.axis2-maven</packageName>
                   <wsdlFile>src/main/resources/service1.wsdl</wsdlFile>
                   <outputDirectory>target/generated-sources</outputDirectory>
                   <syncMode>sync</syncMode>
                </configuration>
            </execution>
            <execution>
                <id>ws2</id>
                <goals>
                    <goal>wsdl2code</goal>
                </goals>
                <configuration>
                   <unpackClasses>true</unpackClasses>
                   <databindingName>adb</databindingName>
                   <packageName>org.example.stackoverflow.axis2-maven</packageName>
                   <wsdlFile>src/main/resources/service2.wsdl</wsdlFile>
                   <outputDirectory>target/generated-sources</outputDirectory>
                   <syncMode>sync</syncMode>
                </configuration>
            </execution>
        </executions>
    </plugin>
guido
  • 18,864
  • 6
  • 70
  • 95
  • Yea, that did it, thanks. Note that POM didn't validate as is. I got: `You cannot have two plugin executions with the same (or missing) elements.` message. After adding a unique `` to each execution, it was all good. – David J. Liszewski Jul 21 '11 at 04:01
  • What if I have 50 WSDL's that needs to be generated. Is this possible using the maven plugin ? – ArunM Aug 05 '13 at 07:09
  • how can I change the output directory location to src/main/java/.. When I am doing it, it is changing the packageName and makes it src.org.example............ How can I resolve this? – AppleBud Jan 17 '14 at 09:11
  • 1
    @AppleBud For the sources directory use the `${project.build.sourceDirectory}` property; however, it is not an healthy practice to generate stuff in the sources directory during the build process. So you better turn off the automatic generation in the `generate-sources` phase, by using ` never` in the execution configuration, and then invoke the goal directly when needed. – guido Jan 17 '14 at 10:38
  • okie, thanks. Is there any way I can make my pom.xml to skip a particular goal? – AppleBud Jan 17 '14 at 10:40
  • 1
    @AppleBud `goal`s are only executed when they are bound to `phase`s defined in the maven build life-cycle. By default, axis2-maven plugin binds to the generate-sources phase, so it get executed. To unbind it, as i said, and assuming you are using maven 3, just use or never (never is a non-existing phase) like described here: http://stackoverflow.com/questions/7800647/in-a-maven-multi-module-project-how-can-i-disable-a-plugin-in-one-child – guido Jan 17 '14 at 10:43
1

i know that is a old question but there is another way to risolve this:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-wsdl2code-maven-plugin</artifactId>
            <version>1.8.2</version>
            <executions>
                <execution>
                    <id>ws1</id>
                    <goals>
                        <goal>wsdl2code</goal>
                    </goals>
                    <configuration>
                        <wsdlFile>src/main/resources/service1.wsdl</wsdlFile>
                    </configuration>
                </execution>
                <execution>
                    <id>ws2</id>
                    <goals>
                        <goal>wsdl2code</goal>
                    </goals>
                    <configuration>
                        <wsdlFile>src/main/resources/service2.wsdl</wsdlFile>
                    </configuration>
                </execution>
            </executions>
            <configuration>
                <unpackClasses>true</unpackClasses>
                <databindingName>adb</databindingName>
                <packageName>org.example.stackoverflow.axis2-maven</packageName>
                <outputDirectory>target/generated-sources</outputDirectory>
                <syncMode>sync</syncMode>
            </configuration>
        </plugin>
    </plugins>
</build>

with that way you have a unique configuration for all wsdl