I demonstrated the usage of Maven2 WSDL2Code plugin in a
previous post. Apache Axis2 provides with a Java2WSDL maven2 plugin as well. Maven2 Java2Wsdl plugin can be used to generate WSDL from a java class. The following steps will help you to create a wsdl from a java class using Axis2 java2wsdl maven plugin.
Step 1
Create a mavan project (See step 1 of ).
Create a java class in the source directory of your maven project. (i.e:- Create Calculator.java class at \src\main\java\com\test directory)
Step 2
Update the pom.xml of your maven project as follows.
<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-java2wsdl-maven-plugin
</artifactId> <executions> <execution> <goals> <goal>java2wsdl</goal> </goals> </execution> </executions> <configuration> <className>com.test.Calculator</className> </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 java2wsdl goal. This goal accepts a set of parameters as explained in
Axis2 online documentation.
In this example we used the simplest configuration parameter,
<className>, which defines the fully qualified name of class from which the WSDL is generated.
Also, make sure to add a dependency to Axis2 jars in your pom.xml.
Step 3Go to the root directory of your project structure and run the following command.
mvn clean axis2-java2wsdl:java2wsdlYou could find the generated wsdl at target\generated-resources\java2wsdl\ directory.