Java 如何在 Tomcat 6 上手动部署 Web 服务?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2511547/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 08:39:53  来源:igfitidea点击:

How to manually deploy a web service on Tomcat 6?

javaweb-servicestomcatdeploymentjax-ws

提问by opensas

I'm learning how to develop SOAP web services with Java.

我正在学习如何使用 Java 开发 SOAP Web 服务。

So far now I've been following this excellent tutorial

到目前为止,我一直在关注这个优秀的教程

http://web.archive.org/web/20120626005333/http://java.sun.com/developer/technicalArticles/J2SE/jax_ws_2/

http://web.archive.org/web/20120626005333/http://java.sun.com/developer/technicalArticles/J2SE/jax_ws_2/

It all goes well, I have my web service working from the command line with it's embedded server and then, with the help of NetBeans I deployed it on Tomcat.

一切顺利,我让我的 Web 服务从命令行使用它的嵌入式服务器工作,然后在 NetBeans 的帮助下,我将它部署在 Tomcat 上。

I'd like to know the steps to manually deploy it on Tomcat, in order to learn how it's done and because I don't like depending on an IDE.

我想知道在 Tomcat 上手动部署它的步骤,以了解它是如何完成的,因为我不喜欢依赖 IDE。

I mean, I'd like to know how everything could be done from the command line and a text editor.

我的意思是,我想知道如何从命令行和文本编辑器完成所有操作。

I've also found this link that explains how to manually deploy a servlet to Tomcat,

我还发现这个链接解释了如何手动将 servlet 部署到 Tomcat,

http://linux-sxs.org/internet_serving/c292.html

http://linux-sxs.org/internet_serving/c292.html

but I couldn't find any article telling how to deploy a web service.

但我找不到任何关于如何部署 Web 服务的文章。

Thanks a lot.

非常感谢。

采纳答案by opensas

How to MANUALLY build and deploy a jax-ws web service to tomcat

如何手动构建 jax-ws Web 服务并将其部署到 tomcat

I was trying to figure out how to MANUALLY build and deploy a web service for learning pourposes.

我试图弄清楚如何手动构建和部署一个网络服务来学习 pourpose。

I began with this excellent article

我从这篇优秀的文章开始

http://java.sun.com/developer/technicalArticles/J2SE/jax_ws_2/(new URL: http://www.oracle.com/technetwork/articles/javase/jax-ws-2-141894.html)

http://java.sun.com/developer/technicalArticles/J2SE/jax_ws_2/(新网址:http: //www.oracle.com/technetwork/articles/javase/jax-ws-2-141894.html

The idea was to do the whole thing using only a notepad and the command line.

这个想法是只使用记事本和命令行来完成整个事情。

The only way I could achieve was by deploying a web service with netbeans, and then having a look at the war generated file at \dist\.war (it's just a zip file, you can open it with 7zip)

我唯一能实现的方法是用netbeans部署一个web服务,然后在\dist\.war中查看war生成的文件(它只是一个zip文件,你可以用7zip打开它)

I leave this in case anybody is interested and for documentation purposes...

我留下这个以防万一有人感兴趣并用于文档目的......

If anybody knows an easier way please let me know!!!

如果有人知道更简单的方法,请告诉我!!!

tested on:

测试:

C:\tomcat6\bin>version
Server version: Apache Tomcat/6.0.26
Server built:   March 9 2010 1805
Server number:  6.0.26.0
OS Name:        Windows XP
OS Version:     5.1
Architecture:   x86
JVM Version:    1.6.0_18-b07
JVM Vendor:     Sun Microsystems Inc.

saludos

问候语

sas

SAS

1. create the following dir c:\java\src\ws

1.创建以下目录 c:\java\src\ws

2. create thew following file c:\java\src\ws\Adder.java

2.创建以下文件 c:\java\src\ws\Adder.java

// c:\java\src\ws\Adder.java
package ws;
import javax.jws.WebService;

@WebService
public class Adder {
 public double add( double value1, double value2 ) {
  return value1 + value2;
 }
}

3. standing at c:\java\src\ execute

3.站在 c:\java\src\ execute

c:\java\src> javac ws\Adder.java

file c:\java\src\ws\Adder.class will be generated

文件 c:\java\src\ws\Adder.class will be generated

4. create the following directory structure with the following files

4.使用以下文件创建以下目录结构

c:\tomcat6\webapps\adder_ws

META-INF
  context.xml
WEB-INF
  classes
    ws
      Adder.class
  lib
    activation.jar
    webservices-api.jar
    webservices-extra.jar
    webservices-extra-api.jar
    webservices-rt.jar
    webservices-tools.jar
  sun-jaxws.xml
  web.xml

5. copy compiled file

5.复制编译文件

copy c:\java\src\ws\Adder.classc:\tomcat6\webapps\adder_ws\WEB-INF\classes\ws\Adder.class

复制 c:\java\src\ws\Adder.classc:\tomcat6\webapps\adder_ws\WEB-INF\classes\ws\Adder.class

6. c:\tomcat6\webapps\adder_ws\META-INF\context.xml

6. c:\tomcat6\webapps\adder_ws\META-INF\context.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/adder_ws"/>

7. c:\tomcat6\webapps\adder_ws\WEB-INF\web.xml

7. c:\tomcat6\webapps\adder_ws\WEB-INF\web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">
    <listener>
        <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>Adder</servlet-name>
        <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Adder</servlet-name>
        <url-pattern>/add</url-pattern>
    </servlet-mapping>
<!-- not needed
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
-->
</web-app>

8. Config WEB-INF\sun-jaxws.xml

8. 配置 WEB-INF\sun-jaxws.xml

file : c:\tomcat6\webapps\adder_ws\WEB-INF\sun-jaxws.xml

文件:c:\tomcat6\webapps\adder_ws\WEB-INF\sun-jaxws.xml

<?xml version="1.0" encoding="UTF-8"?>
<endpoints version="2.0" xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime">
  <endpoint implementation="ws.Adder" name="Adder" url-pattern="/add"/>
</endpoints>

9. Copy libraries

9. 复制库

files at c:\tomcat6\webapps\adder_ws\WEB-INF\lib

文件在 c:\tomcat6\webapps\adder_ws\WEB-INF\lib

copy netbeans files from

从中复制 netbeans 文件

[netbeans dir]\enterprise\modules\ext\metro\*.*

and

[netbeans dir]\ide\modules\ext\jaxb\activation.jar

10. restart apache

10.重启apache

Shutdown : c:\tomcat6\bin\shutdown.bat

关机:c:\tomcat6\bin\shutdown.bat

Startup : c:\tomcat6\bin\startup.bat

启动:c:\tomcat6\bin\startup.bat

11. Test

11. 测试

Open a web browser and go to http://localhost:8080/adder_ws/add?wsdlyou can also use a tool like soapui (http://www.soapui.org/) to test the web service

打开一个网页浏览器,然后转到http://localhost:8080/adder_ws/add?wsdl你也可以使用soapui(http://www.soapui.org/)之类的工具来测试网络服务

that's it, I guess now I'll have a look at the way eclipses does it...

就是这样,我想现在我将看看日食的方式......

回答by Brian Agnew

I would expect the deployable to be the same for a web service and a servlet. Namely, a .warfile. So you should be able to deploy it in the same fashion.

我希望可部署对于 Web 服务和 servlet 是相同的。即,一个.war文件。所以你应该能够以同样的方式部署它。

回答by opensas

here's another useful article

这是另一篇有用的文章

it kind of answer my very own question

它有点回答我自己的问题

http://java.dzone.com/articles/jax-ws-deployment-five-minute

http://java.dzone.com/articles/jax-ws-deployment-five-minute

回答by Vinod Singh

Following articles has step by step guide to manually build and deploy JAX-WS web services. It uses Ant as build tool.

以下文章提供了手动构建和部署 JAX-WS Web 服务的分步指南。它使用 Ant 作为构建工具。

Building JAX-WS Web service

构建 JAX-WS Web 服务

回答by informatik01

I see that nobody has mentioned JAX-WS Tutorialsfrom Mkyong.com.

我看到没有人提到Mkyong.com 的JAX-WS 教程

In the "JAX-WS Security in Tomcat" section on the "JAX-WS Tutorial" page, there is a short, to the point and with pictures tutorial, just what the OP wanted:
Deploy JAX-WS web services on Tomcat

在“JAX-WS 教程”页面的“Tomcat 中的 JAX-WS 安全性”部分中,有一个简短的、重点突出并带有图片的教程,正是 OP 想要的:
在 Tomcat 上部署 JAX-WS Web 服务