HelloWorld service deployment. Eclipse and Tomcat
refer : http://www-inf.it-sudparis.eu/~nguyen_n/teaching_assistant/web_services/simple_web_service_deployment_with_eclipse_and_tomcat_server
Setting up Tomcat on Eclipse
- Download and extract Tomcat (suppose version 7.0.12) on your machine.
- Open the server view on Eclipse by the menu Windows→Show View→Other→Servers.
- Right click on the Server view select New→Server. Let the Server's host name is localhost, select the Server type is Apache→Tomcat v7.0 Server. Click Next.
- Specify the installation directory, such as C:\Program Files\Apache Software Foundation\Tomcat 7.0. Click Finish.
- 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.
HelloWorld service deployment
- Create a Dynamic Web project named WS_HelloWorld by selecting File→New→Dynamic Web Project. Keep the Target Runtime is Apache Tomcat v7.0 and click Finish.
- Open the WS_HelloWorld project, right click on the Java Resources directory, select New→Package. Name it as tps.ws.deployment. Click Finish.
- Create a Java class under the package tps.ws.deployment named HelloWorld.
- 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;
}
} - Right click on the HelloWorld class, select Web Sevices→Create Web service. Verify the Configuration and click Next.
- Select the function sayHello and click Finish.
- The WS skeleton is automatically generate, the service is automatically published on the Eclipse's Tomcat server, and the Tomcat server automatically run.
- A WSDL file is also generated in the WebContent→wsdl folder. We can test our service by right click on this file, select Web Services→Test with Web Services Explorer. Select the sayHello operation and type something in the input. You will see the result like the following:
Publicité
Partager cet article
Pour être informé des derniers articles, inscrivez vous :
Commenter cet article