How to use Maven2 WSDL2Code plugin in Axis2
Apache Axis2 ships with a lot of useful tools to make web service developer's life easier. Maven2 WSDL2Code plugin is one of them which can be used to generate server side skeletons or client stubs from a given WSDL using a maven pom.xml.
Lets see how this plugin can be used.
Pre-requistes:
Apache Maven2
Step1
Create a maven project using maven archetype template (You may ignore this step and use an existing project if you are familiar with maven)
mvn archetype:create -DgroupId=com.test -DartifactId=calculator
This will create a maven project structure as follows.
Step 2
Create a directory (i.e:- resources) at src\main and copy your WSDL file there.
Now, remove the existing contents of the auto-generated pom.xml (calculator\pom.xml) and add the following configuration.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>calculator</artifactId>
<version>1.0-SNAPSHOT</version>
<name>calculator</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-wsdl2code-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>wsdl2code</goal>
</goals>
</execution>
</executions>
<configuration>
<packageName>org.charitha</packageName>
<wsdlFile>src/main/resources/calculator.wsdl</wsdlFile>
<databindingName>adb</databindingName>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
</project>
Note the highlighted elements in the above pom. First we added a new <plugin> to use wsdl2code goal. The WSDL2Code goal takes a set of input parameters as explained here.
In this example, we use 3 configuration parameters.
<packageName> - The generated source will be added to this package
<wsdlFile> - The location of the input wsdl file
<databindingName> - Databinding mechanism used for code generation
Also, we need to add a dependency to Axis2 jars.
Step 3
Go to the root directory of your project structure (i.e:- calculator directory where pom.xml exists) and run the following command.
mvn clean axis2-wsdl2code:wsdl2code
You could find the generated classes at target\generated-sources\axis2\wsdl2code directory.
Note: The sample wsdl used for the above example can be found at http://ww2.wso2.org/~charitha/calculator.wsdl
Lets see how this plugin can be used.
Pre-requistes:
Apache Maven2
Step1
Create a maven project using maven archetype template (You may ignore this step and use an existing project if you are familiar with maven)
mvn archetype:create -DgroupId=com.test -DartifactId=calculator
This will create a maven project structure as follows.
Step 2
Create a directory (i.e:- resources) at src\main and copy your WSDL file there.
Now, remove the existing contents of the auto-generated pom.xml (calculator\pom.xml) and add the following configuration.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>calculator</artifactId>
<version>1.0-SNAPSHOT</version>
<name>calculator</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-wsdl2code-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>wsdl2code</goal>
</goals>
</execution>
</executions>
<configuration>
<packageName>org.charitha</packageName>
<wsdlFile>src/main/resources/calculator.wsdl</wsdlFile>
<databindingName>adb</databindingName>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
</project>
Note the highlighted elements in the above pom. First we added a new <plugin> to use wsdl2code goal. The WSDL2Code goal takes a set of input parameters as explained here.
In this example, we use 3 configuration parameters.
<packageName> - The generated source will be added to this package
<wsdlFile> - The location of the input wsdl file
<databindingName> - Databinding mechanism used for code generation
Also, we need to add a dependency to Axis2 jars.
Step 3
Go to the root directory of your project structure (i.e:- calculator directory where pom.xml exists) and run the following command.
mvn clean axis2-wsdl2code:wsdl2code
You could find the generated classes at target\generated-sources\axis2\wsdl2code directory.
Note: The sample wsdl used for the above example can be found at http://ww2.wso2.org/~charitha/calculator.wsdl
Comments
Thanks for the tips.
However, I am wondering how to dispose several wsdl (different wsdl files, for generating their codes respectively) with this plugin?
Regards,
ye
http://blog.livedoor.jp/lljj332
http://shoes-puma.jugem.jp
http://poloshirts--myfashion.blogspot.com
http://blades.blogsome.com
http://gillettefusion.edublogs.org
D:\Harlan\maven_test\calculator>mvn clean axis2-wsdl2code:wsdl2code
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'axis2-wsdl2code'.
[INFO] org.apache.maven.plugins: checking for updates from central
[INFO] org.codehaus.mojo: checking for updates from central
Downloading: http://repo1.maven.org/maven2/org/apache/axis2/axis2-wsdl2code-mave
n-plugin/1.4/axis2-wsdl2code-maven-plugin-1.4.pom
Downloading: http://repo1.maven.org/maven2/org/apache/axis2/axis2-parent/1.4/axi
s2-parent-1.4.pom
Downloading: http://ws.zones.apache.org/repository2/org/apache/apache/3/apache-3
.pom
Downloading: http://tomcat.apache.org/dev/dist/m2-repository/org/apache/apache/3
/apache-3.pom
Downloading: http://repo1.maven.org/eclipse/org/apache/apache/3/apache-3.pom
Downloading: https://maven-repository.dev.java.net/nonav/repository//org.apache/
poms/apache-3.pom
349b downloaded
[WARNING] *** CHECKSUM FAILED - Checksum failed on download: local = '0f56ee033e
f4b78d33722aceb71a09c7ed68183f'; remote = '
Ugly but true :(
I hope help you.
regards.