Generate jax-ws server and client with maven

For running this example follow these requirements:

  • Jdk: 6 or later
  • Tomcat: ~7

Generate web service implementation

First off, create a maven project with ArchetypeArtifactId = maven-archetype-webapp

Once your maven web project is created, edit pom.xml and add the following lines:

Now let’s create your web service implementation.

Create a class HelloProvider.java and write as follow:

Edit web.xml and add servlet information:

In the same folder WEB-INF add a file called sun-jaxws.xml and put this:

Your web service is ready to be built and deployed.

Run maven clean install and deploy the generated .war file from target folder into tomcat server.

Trying this address

http://localhost:8080/TestWebService/helloProvider?wsdl

should display the wsdl structure.

Generate Web Service Client

Create a simple default project

Edit pom.xml and add the following lines:

Then run maven clean install to generate the client files into target/generated-sources folder.

Please notice:

In order to import wsdl from local file instead of remote url, edit pom.xml in this way:

To access local files, following lines are required

 

Next create JaxWsClient.java file and put this code:

Running this code should write “Hello Fabrizio Starred” on the output.

Windows batch example: building an app and deploy to a remote server

Windows Batch Example

This example will show how to build an application with maven and send the built package to a remote server.

Start installing putty to a whatever directory and set it on the system path under environment variables.

Then place some variables that can be changed in a second moment whenever desired.

The variables are so explained:

workspace: refer to the application source folder,
user_home: is a remote user’s temp folder in which the built package temporarily store.
user: remote user’s account
password: remote password account
mavendir: maven installation folder

Now the first step is to start maven install process.

This command will start maven clean install to another windows (then another process) with wait option in order to wait the execution end of the application (maven install). The ^&^& exit grant the exit from the console in order to automatically continue the statements from the caller process.

will copy through pscp protocol the copy of app.war from local machine to remote server.

Now it’s time to bring the .war to remote server deploy directory, so probably root’s permissions are required.

plink is the command line interface of putty, so using ssh we’ll copy the app.war into deploy directory.

-t option enable pty allocation, so sudo password won’t be asked

-S read the password from the standard input (in this case echo -e %password%

At the same way, using ssh protocol with plink will be possible to call commands to restart the remote server