WS deployment with Eclipse photon (4.8.0) and Tomcat v9 (requires java 1.8)

This tutorial shows how to create a web service using Eclipse for Java EE and deploy it on the Tomcat server. All needed tools are provided in [https://www-inf.telecom-sudparis.eu/~gaaloulw/Downloads/|https://www-inf.telecom-sudparis.eu/~gaaloulw/Downloads/]].

Download Eclipse IDE for Java EE Developers

Setting up Tomcat on Eclipse

  1. Download and extract Tomcat (suppose version 9.0.52) on your machine.
  2. Open the server view on Eclipse by the menu Windows→Show View→Other→Servers.
  3. Right click on the Server view select New→Server. Let the Server's host name is localhost, select the Server type is Apache→Tomcat v9.0 Server. Click Next.


  4. Specify the installation directory, such as C:\Program Files\Apache Software Foundation\Tomcat 9.0. Click Finish.


  5. You can test the server by clicking on the Start and Stop button at the Server view. You can also reconfigure the server by selecting Windows→Preferences→Server→Runtime Environments.

Setting up Axis2 on Eclipse

  1. Apache Axis2 is Web services/SOAP/WSDL engine and is the successor of Apache Axis. It supports both SOAP 1.1 and 1.2.
  2. Download and extract Axis2 1.6.2 binary distribution and extract it on your machine.
  3. Select Window→Preferences on eclipse. Go to Web services→Axis2 Preferences. In Axis2 runtime location browse to your axis2 home folder, for example ~/axis2-1.6.2-bin/axis2-1.6.2. Click Ok.


HelloWorld service deployment

  1. Create a Dynamic Web project named WS_HelloWorld by selecting File→New→Dynamic Web Project. Keep the Target Runtime as Apache Tomcat v9.0. Select the Dynamic web module version as 2.5. In the Configuration part, click on modify and check Axis2 Web Services then click Ok. Click Finish.




  2. Open the WS_HelloWorld project, right click on the Java Resources directory, select New→Package. Name it as tps.ws.deployment. Click Finish.


  3. Create a Java class under the package tps.ws.deployment named HelloWorld.


  4. In the HelloWorld class, create the function sayHello which returns the string “Hello ”+input.

    	package tps.ws.deployment;
     
    	public class HelloWorld {
    		public String sayHello(String input){
    			return "Hello "+input;
    		}	
    	}
  5. Right click on the HelloWorld class, select Web Sevices→Create Web service.
  6. In the Configuration part, select Web service runtime: Apache Axis and select Apache Axis2 in the Web service runtime tab, then click Ok. Click Finish.


  7. The WS skeleton is automatically generated, the service is automatically published on the Eclipse's Tomcat server, and the Tomcat server automatically run.


  8. The WSDL file in axis2 is dynamically generated on service deplyment. To access it from eclipse Web service explorer, right click on WS_HelloWorld project, then Run as→Run on a server. Choose Tomcat v9.0. Click Next.


  9. Make sure that WS_HelloWorld project is in the Configured list. If not add it from Available list to Configured list. Click Finish.


  10. A Welcome page appears.


  11. Select services. A list of available services is presented. Click on HelloWorld service to see the corresponding WSDL file.


  12. To invoke the sayHello operation with the input String from axis2, enter the following url in eclipse web service explorer http://localhost:8080/WS_HelloWorld/services/HelloWorld/sayHello?input=from axis2. If it doesn't work, replace from axis with from%20axis. You will get the response Hello from axis2.


  13. To access your service from your browser, right click on WS_HelloWorld, then select Export→war file. Browse to your tomcat Webapps folder and click Finish.
  14. Start your server from your tomcat bin folder. If it doesn't start, follow the steps below to run the server from the command line.
    1. open the command line and navigate to the tomcat bin folder: cd [path to your tomcat]/bin
    2. Setup JAVA_HOME and PATH variables in the current shell (make sure that you use the same java version used by eclipse). Suppose your java was installed at “/usr/lib/jvm/java-11.0.12”:

          $ export JAVA_HOME=/usr/lib/jvm/java-11.0.12
          $ export PATH=$JAVA_HOME/bin:$PATH
      1. On Windows:
            >set JAVA_HOME=C:\[java home]\jdk11.0.12
            >set PATH=%JAVA_HOME%\bin;%PATH%
  15. start the server by running startup.sh on linux, or startup on windows.
  16. Then enter the following url http://localhost:8080/WS_HelloWorld/services/HelloWorld?wsdl to access to the wsdl file.

Exercises

  1. Modify the server port number in [your tomcat home folder]/conf/server.xml to 8081.
     <Connector port="8081" protocol="HTTP/1.1"
                   connectionTimeout="20000"
                   redirectPort="8443" />
     
  2. Restart your tomcat server. Can you access the service HelloWorld?
  3. Create a simple calculator service with 4 operators: addition, subtraction, multiplication and division.
  4. Create a WS which receives an integer and returns an array of prime numbers less than this integer.
  5. Create a sorting service which sorts an inputed arrays of integers or doubles.
  6. Suppose that your database stores information about persons. Create a service which receives a person ID and returns the name and age of that person.
  7. Create a sorting service which can sorts an input array of person (in the exercise 4) by name or by ID.
teaching_assistant/web_services/simple_web_service_deployment_with_eclipse_and_tomcat_server_v9.txt · Last modified: 2023/09/19 15:00 by IT Courses (NNC)
Back to top
CC Attribution-Share Alike 4.0 International
chimeric.de = chi`s home Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0