Using multiple WSDLs with Axis2 wsdl2code Maven plugin
Asked Answered
P

2

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

Pandolfi answered 21/7, 2011 at 2:41 Comment(0)
I
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>
Inositol answered 21/7, 2011 at 2:50 Comment(6)
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) <id/> elements. message. After adding a unique <id> to each execution, it was all good.Pandolfi
What if I have 50 WSDL's that needs to be generated. Is this possible using the maven plugin ?Nichols
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?Pestilence
@Pestilence 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 ` <phase>never</phase>` in the execution configuration, and then invoke the goal directly when needed.Inositol
okie, thanks. Is there any way I can make my pom.xml to skip a particular goal?Pestilence
@Pestilence goals are only executed when they are bound to phases 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 <phase/> or <phase>never</phase> (never is a non-existing phase) like described here: #7801147Inositol
E
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

Ethical answered 19/7, 2023 at 13:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.