Creating a client jar from SOAP wsdl

I am trying to interact with some SOAP web services that have basic authentication and I have url, username and password. Now I want to use this web service in my java code, so I need to create a jar file for it.

I saw the URLs below, but not sure if I did this correctly. http://axis.apache.org/axis2/java/core/docs/userguide-creatingclients.html#choosingclient http://javasourcecodeetc.blogspot.com/2011/07/convert-wsdl-to-java-for-calling -soap.html

I downloaded the 2-1.6.2 axis from http://axis.apache.org/axis2/java/core/download.cgi (binary distribution only)

I have a client stub that was given ... I see people say to use it with build.xml, but I could not find build.xml anywhere .... Please tell me what I need install to configure the apache and ant axis? What does ant do here?

+7
java soap web-services apache ant
source share
2 answers

Marking the answer works, but I'm more of a Maven guy and I want to ultimately stun the exit bank.

Here's how to do it with Maven.

  • Download the WSDL to a directory (e.g. mydir/MyWsdl.wsdl ).
  • Create a pom.xml file (as shown below).
  • Run mvn package .

Here you will get

 └── mydir β”œβ”€β”€ MyWsdl.wsdl β”œβ”€β”€ pom.xml └── target (add this dir to .gitignore) β”œβ”€β”€ generated-sources β”œβ”€β”€ mywsdl-0.1.0-SNAPSHOT.jar β”œβ”€β”€ mywsdl-0.1.0-SNAPSHOT-sources.jar └── mywsdl-0.1.0-SNAPSHOT-javadoc.jar 

And the source of the pom.xml file

 <?xml version="1.0" encoding="UTF-8"?> <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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>mywsdl</artifactId> <version>0.1.0-SNAPSHOT</version> <name>My WSDL client</name> <build> <plugins> <!-- Generates JAVA source files from the WSDL --> <plugin> <groupId>org.apache.axis2</groupId> <artifactId>axis2-wsdl2code-maven-plugin</artifactId> <version>1.6.2</version> <executions> <execution> <goals> <goal>wsdl2code</goal> </goals> <configuration> <packageName>com.example</packageName> <wsdlFile>MyWsdl.wsdl</wsdlFile> <!-- TODO: Update this file with new WSDL versions --> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <executions> <execution> <id>attach-sources</id> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <executions> <execution> <id>attach-javadocs</id> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2</artifactId> <version>1.6.2</version> </dependency> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-adb</artifactId> <version>1.6.2</version> </dependency> <dependency> <groupId>org.apache.ws.commons.axiom</groupId> <artifactId>axiom-api</artifactId> <version>1.2.14</version> </dependency> <dependency> <groupId>org.apache.ws.commons.axiom</groupId> <artifactId>axiom-impl</artifactId> <version>1.2.14</version> </dependency> </dependencies> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> </project> 
+9
source share

Axis2 supports several ways to support Web services clients. The most common approach is documented here and involves generating Java code that parses the SOAP message described in the WSDL file.

The following answer describes several ways to invoke a web service. The last part describes a groovy script that uses the classes generated by Axis2 and compiled using ANT:

  • Steps to Create a Web Service Using Axis2 - Client Code

More details

The wsdl2java program (bundled with Axis2) will generate an ANT project based on the specified WSDL file:

 $AXIS2_HOME/bin/wsdl2java.sh -d adb -s -o mydir -uri http://www.xmlme.com/WSShakespeare.asmx?WSDL 

This will create the following files:

 └── mydir β”œβ”€β”€ build.xml └── src └── com └── xmlme └── webservices └── ShakespeareStub.java 

If you check the generated Java code, you will find java classes that match the types of XML schemas defined in the WSDL file, which will simplify serialization and deserialization of SOAP messages.

The "build.xml" file contains the logic that will compile the generated Java code.

 cd mydir ant 

When you start the build by default, a jar file will be created as follows:

 └── mydir β”œβ”€β”€ build β”‚  β”œβ”€β”€ classes β”‚  β”‚  └── .. β”‚  β”‚  .. β”‚  └── lib β”‚  └── Shakespeare-test-client.jar β”œβ”€β”€ build.xml └── src └── com └── xmlme └── webservices └── ShakespeareStub.java 

This jar file can now be included in java (or see my groovy script example in another answer ) that wants to access the web service.

+7
source share

All Articles