Step by Step JAX-WS Web Services with Eclipse, TomEE, and Apache CXF

This is a step by step tutorial to try out JAX-WS web services using Eclipse, TomEE, and CXF. There will not be a need to use maven and all configuration and preparation will be done manually using Eclipse.

Sandbox Environment

  • Sandbox OS : Windows 7 64 bit
  • JDK : Java SE Development Kit 7. <Link>
  • IDE : Eclipse IDE for Java EE Developers, Version Juno <Link>
  • App Server: Apache TomEE is a Java EE application server built on top of Tomcat <Link>
  • JAX-WS Runtime: Apache CXF that is bundled in TomEE container. <Link>

Download and installation

  • Download “Windows x64” JDK 7 from here. Install JDK by double clicking on the downloaded .exe file.
  • Download Eclipse from here. Expand the zip folder onto a folder location of your choice. We will be referring to this location as “<Eclipse_home>”.
  • Download TomEE from here. Expand the zip folder onto a folder location of your choice. We will be referring to this location as “<TomEE_Home>”

Steps and Discussion

Steps and source code are developed mostly customizing the tutorial “JAX-WS @WebService example” provided at TomEE site at location .

Write Web Services Code

  • Start Eclipse IDE by clicking <Eclipse_Home>\eclipse.exe


  • Click File > New > Other…


  • Type in “dynamic Web Project” in Wizards input box. Dynamic Web Project wizard should show up for selection. Select “Dynamic Web Project”. Click “Next” button.


  • Type in “WebServicesExperiment” in Project name input box.


  • Click “New Runtime…” button. A “New Server Runtime Environment” dialog box shows up. Expand “Apache” and select “Apache Tomcat v7.0”. Click “Next” button.


  • Type in “TomEE Runtime” on “Name” input box. Click “Browse…” button to selection TomEE installed location which is being referred to as “<TomEE_Home>”. For example for the laptop that was used for this tutorial, <TomEE_Home> location is “S:\servers\apache-tomee-plus-1.5.1”. Click “Finish” button.


  • Click “Finish” button again on “New Dynamic Web Project” dialog box.
  • Select Window > Show View > Navigator. Your Eclipse window should look similar to below.


  • Select File > New > Other… and type in “Class”. This should make “Class” wizard visible on dialog box. Select “Class” and click “Next” button to view “New Java Class”
  • Type “HelloTomEEWs” as Name and click Finish.
  • Type in the following code and save the java class HelloTomEEWs. HelloTomEEWs is the interface for the web service that we are creating.
import javax.jws.WebService;

@WebService(targetNamespace = "")
public interface HelloTomEEWs {

    public int sum(int add1, int add2);

    public int multiply(int mul1, int mul2);
  • Create another class named “HelloTomEEIMplementation . HelloTomEEIMplementation is the implementation web services. Type in code as below.
import javax.ejb.Stateless;
import javax.jws.WebService;

        portName = "HelloTomEEPort",
        serviceName = "HelloTomEEService",
        targetNamespace = "",
        endpointInterface = "HelloTomEEWs")
public class HelloTomEEIMplementation implements HelloTomEEWs {

    public int sum(int add1, int add2) {
        return add1 + add2;

    public int multiply(int mul1, int mul2) {
        return mul1 * mul2;

Deploy WAR

  • Now select menu item File > Export… > Web > War file
  • Click Next button
  • Select “WebServicesExperiment” project from “Web project: drop down menu if it is no already selected.
  • On Destination: input box click “Browse” button.
  • Navigate to <TomEE_Home>\webapps and click “Save” button. This action should have “WebServicesExperiment.war” with full folder path location on Destination input box.
  • Select “TomEE Runtime” from Target runtime drop down box right under the check box named “Optimize for a specific server runtime. The “Expoert” window should look like below.


  • Click “Finish” button. This action should produce a WAR  under <TomEE_Home>\webapps folder.
  • Click windows Start > All Programs > Accessories > Command Prompt to bring up a Command Console
  • Change Directory CD to <TomEE_Home>\bin folder location.
  • For example TomEE installation location on the machine that was used for this blog was


Run TomEE

  • Set JAVA_HOME environment variable to <Java_Home>.
  • Where jdk has been installed in S:\JDKs\64bit\jdk1.7.0_05 on the machine that was used to create this blog example.
  • The following command has been used to set Java_Home.

SET JAVA_HOME=S:\JDKs\64bit\jdk1.7.0_05

  • Start TomEE by typing startup in the command prompt. This action will bring up another command prompt with a title “Tomcat”. After spitting out a lot of system log the windows should stabilized with a line like “INFO: Server startup in 2560 ms” or something similar



  • Fire up a Firefox browser.
  • Type in the following url to view the WSDL of the web services that is running off of TomEE server


  • You should see WSDL on Firefox


  • Note: It took a little bit time to find the WSDL url. Apache TomEE has a “Admin GUI” window. The url to WSDL was found logging in to TomEE Adming GUI and clicking on Console button. The consol button brought up a dialog box where the details of the web services were displayed.

Testing with soapUI

  • Download and install SoapUI from
  • Start SoapUI
  • Select menu item File > New soapUI Project to bring up “New soapUI Project” dialog box.
  • Type in TomEE SoapUI Test in “Project Name” input box
  • Paste WSDL url on “Initial WSDL/WADL:” input box. For example for this blog example the wsdl is


  • Click OK button


  • Double Click “Request 1” under multiply


  • Type in 4 between <arg0> and </arg0>
  • Type in 6 between <arg1> and </arg1>
  • Click Green Arrow button on top left to POST soap request to TomEE web service.


  • Server returns a soap message back with result 24


Testing With Firefox SOA Extension “Poser”


  • A soap message should be returned from the server with a result of 24 as shown below.


Test with Java Web Services Client

  • Open up Eclipse if it is not running already.
  • Create File > New > Java Project
  • Type TomEEClient on Project name: input box
  • Click “Finish”
  • Eclipse will ask for your permission to change perspective to “Java”. Select Yes.
  • On “Project Explorer” pane on the left right click on project “TomEEClient” and select “Properties” from the bottom of the dialog box.
  • Select “Java Build Path” from left pane.
  • Click on “Libraries” tab from right pane.
  • Then click on “Add Library…” button from right.


  • “Add Library” dialog box shows up.
  • Select “Server Runtime” from left pane and click “Next” button


  • Select  already configured from previous project “TomEE Runtime” and click “Finish” button


  • Click “OK” button to get out of “Properties for TomEEClient” window.
  • Right click on “src” from left pane and select “Class” wizard.


import javax.ejb.embeddable.EJBContainer;
import javax.xml.namespace.QName;

import java.util.Properties;

public class TomEECalculatorClient {

	public static void main (String[] args) throws Exception{
		Properties properties = new Properties();
        properties.setProperty("openejb.embedded.remotable", "true");

        Service calculatorService = Service.create(
                new URL("http://localhost:8080/WebServicesExperiment/webservices/HelloTomEEIMplementation?wsdl"),
                new QName("", "HelloTomEEService"));
        HelloTomEEWs calculator = calculatorService.getPort(HelloTomEEWs.class);
        System.out.println("Sum of 10 and 10 is : " + calculator.sum(10, 10));
        System.out.println("Multiple of 10 and 10 is : " + calculator.multiply(10, 10));
  • Two Java code that was written as service interface and implementation for the previous web services project will need to be copied over to this client code as well. To make things simple this blog example is not using wsimport to generate Java artifacts from WSDL url as usually done as standard practice.
  • The Package Explorer pane should look like bellow with all three Java classes.


  • Now right click on “” and select “Run As” > “Java Application”
  • Java client should get results back from the server and the Console window of Eclipse should display result as below.


Some Notes

  • TomEE container is configured and packaged with Apache CXF runtime and required libraries. TomEE relieves you from configuration a web component only container like Tomcat with Apache CXF. That is the main selling point of TomEE that it enables you to write fully loaded JEE application server applications.
  • Selecting TomEE as runtime from within Eclipse also relieves a developer from using build tools like maven. Maven is a wonderful tool and it should be used a lot. However, sometime maven is tough to use specially if a person is developing behind a very strict company firewall where even a proxy is not allowed. In this kind of situation manual configuration is more desired.


  1. April 24, 2013 Reply
  2. mitchp May 2, 2013 Reply
  3. Alex May 13, 2013 Reply
    • Alex May 13, 2013 Reply
  4. SreePreeti June 17, 2013 Reply
    • Ear2ear September 27, 2013 Reply
      • Ritabh August 7, 2014 Reply
    • Ajay Venkatesh December 15, 2017 Reply
  5. quency August 8, 2013 Reply
    • Eduardo Rotundo August 14, 2013 Reply
      • Aamod November 12, 2013 Reply
        • Eduardo Rotundo November 15, 2013 Reply
          • Aamod November 15, 2013
          • Eduardo Rotundo November 18, 2013
  6. Max September 4, 2013 Reply
  7. Saurav November 28, 2013 Reply
    • Eduardo Rotundo December 12, 2013 Reply
      • Venu December 17, 2013 Reply
        • Eduardo Rotundo December 24, 2013 Reply
          • Sankalp January 2, 2014
  8. Venu December 17, 2013 Reply
  9. Kumara February 24, 2014 Reply
    • Ritabh August 7, 2014 Reply
    • martinchenier October 9, 2015 Reply
  10. Thali July 24, 2014 Reply
  11. David Clifte September 10, 2014 Reply
  12. Atul July 28, 2015 Reply
  13. Ardi Nusawan April 19, 2016 Reply
  14. Ajay Venkatesh December 15, 2017 Reply

Add a Comment

Your email address will not be published. Required fields are marked *