Tomcat web service release tutorial

Source: Internet
Author: User

I have been preparing for a job these days. I learned some basic content about Web Service and encountered many problems. Now I will share with you what I have learned. As I am a beginner, please correct me for any errors. Thank you ~~!!

1. Download the Jax-ws dependency package

Because Tomcat does not have the dependent environment required by Jax-WS, the first step is to download the Jax-ws Ri, that is, the Jax-ws reference implemantation, address: http://jax-ws.java.net.

2,Install JAX-WS Ri On the Tomcat server

First download ant and Tomcat and set Environment VariablesAnt_home and catalina_home, and then introduce their respective bin directories under pathOpen the command prompt and run ant install in the directory of the Jax-ws Ri package.


This command will directly import the required package to the $ {Tomcat} \ shared \ lib directory, in fact, the package under jaxws Ri Lib is copied to shared \ Lib under the tomcat installation directory.

3,Set tomcat in eclipse

Because eclipse is a custom tomcat configuration file, you need to add something to add shared \ Lib,Open the ctalina. properties file.



(Excerpt ):

# Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. see the notice file distributed with # This work for additional information regarding copyright ownership. # The ASF licenses this file to you under the Apache license, version 2.0 # (the "License"); you may not use this file except T in compliance with # the license. you may obtain a copy of the license at # http://www.apache.org/licenses/LICENSE-2.0## unless required by applicable law or agreed to in writing, software # distributed under the license is distributed on an "as is" basis, # Without warranties or conditions of any kind, either express or implied. # See the license for the specific language governing permissions and # limitations under the license. # list of comma-separated packages that start with or equal this string # will cause a security exception to be thrown when # passed to checkpackageaccess unless the # corresponding runtimepermission ("accessclassinpackage. "+ package) has # been granted. package. access = sun ., org. apache. catalina ., org. apache. coyote ., org. apache. tomcat ., org. apache. jasper. # list of comma-separated packages that start with or equal this string # will cause a security exception to be thrown when # passed to checkpackagedefinition unless the # corresponding runtimepermission ("defineclassinpackage. "+ package) has # been granted. # by default, no packages are restricted for definition, And none of # The class loaders supplied with the JDK call checkpackagedefinition. # package. definition = sun ., java ., org. apache. catalina ., org. apache. coyote ., org. apache. tomcat ., org. apache. jasper. ### list of comma-separated paths defining the contents of the "common" # classloader. prefixes shoshould be used to define what is the repository type. # path may be relative to the catalina_home or catalina_base path or absolute. # If left as blank, the JVM system loader will be used as Catalina's "common" # loader. # examples: # "foo": Add this folder as a class repository # "foo /*. jar ": Add all the jars of the specified folder as class # repositories #" foo/bar. jar ": Add bar. jar as a class repositorycommon. loader =$ {Catalina. home}/shared/lib /*. jar, $ {Catalina. home}/shared/lib, $ {Catalina. base}/lib, $ {Catalina. base}/lib /*. jar, $ {Catalina. home}/lib, $ {Catalina. home}/lib /*. jar

 

Find the common. loader configuration item and add$ {Catalina. Home}/shared/Lib/*. Jar, $ {Catalina. Home}/shared/lib These two paths are enough.

4. Create a project

Create a web project, webservice_web. The directory structure is as follows:


 

Helloservice. Java is an interface that provides Web Services,CodeAs follows:

Package com. zxuqian. WebService; import javax. JWS. webmethod; import javax. JWS. WebService; @ webservicepublic interface helloservice {@ webmethod string greetings (string name );}

Helloserviceimpl. Java is an implementation class and the code is as follows:

 
Package COM. zxuqian. webService. impl; import javax. JWS. webService; import COM. zxuqian. webService. helloservice; @ WebService (endpointinterface = "com. zxuqian. webService. helloservice ") public class helloserviceimpl implements helloservice {@ override Public String greetings (string name) {return" Hello: "+ name ;}}

5. Add sun-jaxws.xml

The sun-jaxws.xml is a Web-based Web Service Application description file, the content is as follows:

 

 
<? XML version = "1.0" encoding = "UTF-8"?> <Endpoints xmlns = "http://java.sun.com/xml/ns/jax-ws/ri/runtime" version = "2.0"> <endpoint name = "helloworld" implementation = "com. zxuqian. webService. impl. helloserviceimpl "url-pattern ="/Hello "/> </endpoints>

 

For more information about each node, see the docs document in the jaxws Ri package.
The interface and implementation class of the web service and its URL relative path

6. Configure web. xml

the content is as follows:

 
   
   
   
     webservice_web 
    
   
     COM. sun. XML. WS. transport. HTTP. servlet. wsservletcontextlistener 
     
   
     Hello 
    
   
     COM. sun. XML. WS. transport. HTTP. servlet. wsservlet 
    
   
     1 
     
    
    
      Hello 
      
     
      /Hello 
      
    
    
   

7. Test

Start Tomcat and enter the Web service address http: // localhost: 8088/webservice_web/hello in the browser. The Tomcat port number is 8088. Modify the port number accordingly.

8. References

Http://www.mkyong.com/webservices/jax-ws/deploy-jax-ws-web-services-on-tomcat/

 

 

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.