WS deploying Web SERVICE in Tomcat

Source: Internet
Author: User
Tags xmlns tomcat wsdl
Deploying Web SERVICE in Tomcat Oh, it took an afternoon to finally fix it, now tidy up the idea.    This is a simple Web service example where the client sends a name to the server and the server returns a "Hello + name" string. 1. Download Jaxws-2_0.jar, address https://jax-ws.dev.java.net/This step is killing me, the following example uses the class in this package, but the textbook does not mention that the results are always prompt for errors when deployed to Tomcat, So I went through the Tomcat and JDK class package, the results can not find the corresponding class, Baidu search, found all with axis to configure, and ran to Google to search, the Chinese page did not mention, and finally in the foreign forum to find the answer, tragedy ah, wasted so much time.  
This is the reason I wrote this tutorial, no one pointed out, Stones is a cup.  
2. Create a new WS directory under the Tomcat WebApps directory, creating a new Web-inf directory below, web-inf the classes and LIB directories under the directory. 3. Unzip the jar package downloaded in the 1th step and copy all the files under the Lib directory to the Lib directory created in step 2nd 4. Create a new directory under the classes directory HelloWorld 5. In the HelloWorld directory to create the SEI (service Endpoint Interface, that is, the services endpoint interface, in fact, a annotated interface, but ws like so called), the content is as follows//helloworld.java package    HelloWorld    Import javax.jws.*;  @WebService public interface HelloWorld {@WebMethod string hello (string name); } 6.    Create the SIB (service implementation Bean, which is also the custom in WS)//helloworldimpl.java package HelloWorld;    Import javax.jws.*; @WebService (endpointinterface = "HelloWorld". HelloWorld ") public class Helloworldimpl implements HelloWorld {public StrinG Hello (String name) {return "Hello," + name; }} 7. Compile, go to cmd, cut to classes directory, Javac Helloworld/*.java 8. Generates a jax-b artifact (artifacts), which generates a JAXWS directory in HelloWorld directory, WSGEN-CP. HelloWorld. Helloworldimpl 9. Create a new Web. XML in Web-inf, configured as follows:
 <?xml version= "1.0" encoding= "UTF-8"?> <web-app xmlns= "Http://java.sun.com/xml/ns/javaee"   xmlns
: xsi= "http://www.w3.org/2001/XMLSchema-instance"   xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee                        http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd "  version=" 3.0 ">    < servlet>  <servlet-name>HelloWorldWS</servlet-name>  <servlet-class>    Com.sun.xml.ws.transport.http.servlet.WSServlet  </servlet-class> </servlet> <servlet-mapping >  <servlet-name>HelloWorldWS</servlet-name>  <url-pattern>/helloworld</ Url-pattern> </servlet-mapping> 
<listener>
<listener-class>
Com.sun.xml.ws.transport.http.servlet.WSServletContextListener
</listener-class>
</listener>
</web-app>
Where listener is used to parse sun-jaxws.xml files.
10. Create Sun-jaxws.xml again, this file provides a Web service endpoint to connect Wsservlet instances and service implementation classes.
<?xml version= "1.0" encoding= "UTF-8"?> <endpoints
xmlns= "http://java.sun.com/xml/ns/jax-ws/ri/ Runtime "version=" 2.0 ">
<endpoint 
name=" Helloworldws "implementation=" HelloWorld
. Helloworldimpl "
url-pattern="/helloworld "/>
</endpoints>
 11. In this way, the server side is complete, start Tomcat, enter HTTP://LOCALHOST:8080/WS/HELLOWORLD?WSDL in the browser to see the WSDL file 12. Next write a client to test the service 13. First First, use Wsimport to generate the required artifacts for the client, Wsimport-keep-p http://localhost:8080/ws/helloworld?wsdl 14.    Create a new Client.java file under the client directory generated in the previous step package client; public class Client {public static void main (string[] args) {Helloworldimplservice service = new Helloworldimplserv    Ice ();        HelloWorld port = Service.gethelloworldimplport ();   System.out.println (Port.hello ("Old Horse")); }} 15. Compile the Javac client. Client.java, run the Java client. Client. Can see the on-screen display of Hello, old horse 16.  
Whistling, finally finished, writing tutorials is really tired than writing code ... 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.