Search This Blog

Tuesday, February 24, 2015

SOAP Webservice using CXF and Maven

In this post, we will see how to create a JAX-WS SOAP based webservice and a client using Apache CXF and Maven. Infact, this can be done without writing a single line of code.
Find below the step by step process to create one:

1. Create the project structure and sample files using the below command:



mvn archetype:generate -DgroupId=com.learninjava -DartifactId=testjaxrsws -DarchetypeArtifactId=org.apache.cxf.archetype:cxf-jaxws-javafirst -DinteractiveMode=false


Note:
If you are seeing weird errors when you run the above command then you can use the below command :


mvn archetype:generate

then maven will list all the archetypes available, select the number referring to the archetype "org.apache.cxf.archetype:cxf-jaxws-javafirst".

If you are unable to see the entire list, then write the list to a file and find the appropriate archetype in the persisted file.

Command to write the archetypes list to a file :

mvn archetype:generate > archetypes.txt

2. Start the server and webservice


The above command will create basic project structure and all the required files and configuration. Open pom.xml and you can see the tomcat plugin is also added. We will use this plugin for our server. Use the below command to start tomcat :

mvn clean install -DskipTests=true tomcat7:run


3.

i. Test using browser


Open the browser and navigate to the below URL :

http://<host>:<port>/jaxws-service/helloWorld/echo/learninjava

ii. Test using client


Run the below command to run the client :

mvn test

Note:
1. Make sure the server is running before the client is started
2. Make sure the test file name has the name "Test" in it, otherwise maven
simply ignores the file thinking of it as non test source file.

For detailed information on creating a JAX-WS SOAP webservice, refer
http://www.learninjava.com/pages/jaxws-soap-webservice-using-cxf.php

No comments: