Create a webservice using Jax Ws JBOSS


By Rodrigo

Created 2015-06-28 22:32:35 Modified 2015-06-28 22:47:11

Java api for xml webservices (Jax-Ws) is the "standard" or "core" api to develop webservices, is part of the JEE platform, therefore if we're working with some application server there's no need to add third party libraries, as in the case of tomcat

In this tutorial we are going to develop 2 @webservice methods within a webservice which will return a String and an int value

this tutorial was written using the following gear:

  • Hardware:           laptop Thinkpad X1 carbon Intel I7, 8gb Ram, 256gb SDD
  • OS:                    x86_64 GNU/Linux Ubuntu 15.04
  • Kernel:               3.19.0-21-generic
  • IDE/Text editor:   Eclipse Java EE IDE for Web Developers Version: Luna Service Release 2 (4.4.2)
  • JDK:                   Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
  • Jboss:                 jboss-as-7.1.1.Final
  • Browser:             Versión 43.0.2357.81 Ubuntu 15.04 (64-bit)


1.- Creating the web service project:

go to eclipse file => new => Project... and type dynamic, choose the "Dynamic web project" and click next


here type the project name "jaxWs" and click finish



2.- Creating the classes:

Now we are ready to develop our webservice methods, let's create the interface with the WS methods, click new Class and create the JaxWsExample class (then change to interface) under com.rrivero.webservices package

package com.rrivero.webservices;

import javax.jws.WebMethod;
import javax.jws.WebResult;
import javax.jws.WebParam;
import javax.jws.WebService;

 * @author Rodrigo Rivero
 * @since 10-06-2015

public interface JaxWsExample {

	int suma(
		@WebParam(name = "n1") int n1,
		@WebParam(name = "n2") int n2
	String saludo(
		@WebParam(name = "nombre")String nombre

now create the implementation of the previous interface under com.rrivero.webservices.impl package

package com.rrivero.webservices.impl;

import javax.jws.WebService;

import com.rrivero.webservices.JaxWsExample;

@WebService(endpointInterface = "com.rrivero.webservices.JaxWsExample")
public class JaxWsExampleImpl implements JaxWsExample {

	public int suma(int n1, int n2) {
		return n1+n2;

	public String saludo(String nombre) {
		return "Hola "+ nombre;

Once we have created the classes les't add the web.xml (just to be fancy, is not really necessary)

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                id="WebApp_ID" version="3.0">


now we should get the following tree in our project's directory

3.- Testing the webservice:

Up to this point we are done, start the jboss server and go to you'll see the following page:


now go to soapUi and test the webservice, right click on "Projects" -> new soapUi project and paste the url to your wsdl, click ok


we should get the following screen, then test it



Download it in https://drive.google.com/file/d/0BwOqSob-RrBOWm12bm1feUJ6UWs/view?usp=sharing

6.- Conclusion:

As you may see Jax-Ws is the easiest way to get on with java webservices, you don't need extra configuration, no third party libraries, you just go straight to develop your webservice

7.- Reference links:


comments powered by Disqus