How to deploy your JAXWS web service in Axis2

Apache Axis2 provides the facility of deploying JAXWS web services. If you have a JAXWS web service which is written using standard JAXWS annotations, this post will help you to deploy your service in Axis2.

Step 1 : Create a .jar file including your .class files with their packages. Structure of a sample service is shown below.

service-structure

If you have a WSDL for your service, you can include the WSDL in the root level of the jar file and add the “wsdlLocation” within your “@WebService” annotation which is in your service class. And also you have to provide “serviceName” and “portName” as it is in the WSDL. A Sample annotation is shown below.

@WebService(
name=”PersonService”,
targetNamespace=”http://personservice”,
serviceName=”PersonServicePorts”,
portName=”PersonService”,
wsdlLocation=”PersonService.wsdl”
)

If you don’t include the WSDL in your service, Axis2 will try to generate the WSDL for you. But it is better to include your WSDL rather than depending on the generated WSDL. For complex services, WSDL generation may fail.

If you have any libraries on which your service is depending on, you can include those in a “lib” folder at the root level of your .jar archive.

Following image shows the root level structure of your .jar file. WSDL and the “lib” folder are optional.

lib-wsdl

Step 2 : Download Axis2 1.5 binary distribution (or you can build Axis2 trunk from the source) and extract it. Create a AXIS2_HOME/repository/servicejars directory and copy your .jar file which is created in Step 1 into servicejars directory.

Step 3 : JAXWS WSDL generation depends on jaxws-rt.jar and jaxws-tools.jar files. So you have to download them and copy both into the AXIS2_HOME/lib directory.

Step 4 : Start the server using AXIS2_HOME/bin/axis2server.sh (or .bat). You can see an INFO log on the console on the service deployment.

Step 5 : Access http://localhost:8080/axis2/services from your browser. You can see the deployed JAXWS service and you can see the WSDL by clicking on it. Use some tool like “soapui” to invoke the service by providing the WSDL URL.