Tomcat web service deployment

Source: Internet
Author: User
Yiyun development team if you want to develop Web services under Tomcat, download jaxws.zip,: example...

 

I. deployment before development

If you want to develop Web services under tomcat, then you need to download jaxws.zip,: http://jax-ws.java.net/2.2.5/

To create a web service, deploy it in the following Directory:

 

 

Medium:

Place the jar package in jaxws.zip in lib;

Classes stores the SIB and SEI of the web service (if it is style = document, the wsgen tool is also required to generate the type );

Sun-jaxws.xml is a web service-specific configuration file;

 

Here, WEBROOT is assumed to be the ws folder;

 

2. development steps

 

1. write SEI

 

Package org. xiazdong. ws;

Import javax. jws .*;

@ WebService

Public interface TempConvert {

@ WebMethod int f2c (int I );

@ WebMethod int c2f (int I );

 

}

 

2. compile SIB

 

Package org. xiazdong. ws;

Import javax. jws .*;

@ WebService (endpointInterface = "org. xiazdong. ws. TempConvert ")

 

Public class TempConvertImpl implements TempConvert {

Public int f2c (int I ){

Return I-5;

}

Public int c2f (int I ){

Return I + 5;

}

}

 

3. Compile the above two files;

Javac-d. *. java

 

4. generate types using the wsgen tool

 

Wsgen-cp. org. xiazdong. ws. TempConvertImpl

 

5. compile web. xml

 

 

 

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_2_5.xsd"

Version = "2.5">

 

Com. sun. xml. ws. transport. http. servlet. WSServletContextListener  

 

TimeServerWS  

Com. sun. xml. ws. transport. http. servlet. WSServlet  

 

TimeServerWS  

/Ws  

 

 

 

6. write sun-jaxws.xml

 

 

 

Name = "TimeServerWS"

Implementation = "org. xiazdong. ws. TempConvertImpl"

Url-pattern = "/ws"/>

 

 

 

7. Arrange these files according to the directory layout;

 

Finally, enter http: // localhost: 8080/ws? Check whether the wsdl exists. If yes, the deployment is correct;

 

3. call services

 

1. use the wsimport tool

 

Wsimport-keep-p client http: // localhost: 8080/ws? Wsdl

Generate service code;

 

2. Compile the call client www.2cto.com

 

 

Import client .*;

Public class TimeClient {

Public static void main (String args []) {

TempConvertImplService service = new TempConvertImplService ();

TempConvert c = service. getTempConvertImplPort ();

System. out. println (c. f2C (5 ));

}

}

 

From xiaozdong

Related Article

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.