如何将jax-ws服务部署到eclipse或tomcat?

发布于 2024-09-08 09:04:41 字数 1058 浏览 0 评论 0 原文

作为一名 Web 服务初学者,我已经尝试了 2 周来获得一个与 Maven、Eclipse 和 Tomcat 一起使用的 hello World Web 服务。

我放弃了尝试让任何代码/wsdl 生成器正常工作,并按照本教程进行操作 http://myarch.com/create-jax-ws-service-in-5-minutes 手动编写一个示例,这非常棒。

这会产生 4 个类文件和一个 WSDL 文件。

所以我的愚蠢问题是如何在 eclipse 和/或 tomcat 上“运行”服务?

我尝试将它们部署为 web 应用程序,但没有任何乐趣 - web.xml 中没有任何内容可以告诉 servlet 引擎 Web 服务存在,所以我猜它永远无法工作。

我是否必须在 tomcat 中拥有一个特殊的 Web 服务容器(例如 axis2、metro 或 CXF)并部署到该容器?或者它可以只使用一些 jax-ws jars + 神秘配置运行吗?

我不想安装到 tomcat Metro(它使用 ant,并且是为 glassfish 设计的)或 axis2(它使用 ant,大多数人似乎不推荐)。

我查看了 CXF,但在他们的网站上找不到任何关于如何在没有 spring 的情况下在 tomcat(或 eclipse)上安装/配置它的信息。我将 CFX jar 放入 Maven 依赖项中,并安装了 Eclipse 插件,但这会让您更接近实际运行 Web 服务,而无需神秘的配置胶水。 CXF 似乎与 spring 紧密相关,这对我们来说是一个很大的缺点,因为我们不使用 spring(或需要它的任何功能)。

我注意到 helios wtp 有某种名为 JSR-109 的 Web 服务项目。这是仅 java RPC,还是支持完整的 SOAP webservices 系统,是否值得尝试弄清楚?

非常欢迎任何建议。我必须在 google 上搜索 1000 个页面才能找到 Web 服务的圣杯 - 即如何端到端地创建和部署一个到 tomcat。应该这么难吗?

As a web services beginner, I have tried for 2 weeks to get a hello world webservice working with maven, eclipse and tomcat.

I gave up trying to get any of the code/wsdl generators to work, and I followed this tutorial http://myarch.com/create-jax-ws-service-in-5-minutes to hand code an example, which is brilliant.

This results in 4 class files and a WSDL file.

So my stupid question is how to "run" the service in eclipse and/or on tomcat?

I tried just deploying them as a webapp, but no joy - there is nothing in the web.xml to tell the servlet engine that the web service exists, so I guess it could never work.

Do I have to have a special web service container (e.g. axis2, metro or CXF) inside tomcat, and deploy to that? Or can it just run with some jax-ws jars + mystery configuration?

I dont want to have to install into tomcat metro (which uses ant, and is desiged for glassfish), or axis2 (which uses ant, and most people seem to not recommend).

I looked at CXF, but cant find anywhere on their site on how to install/configure it on tomcat (or eclipse) without spring. I put the CFX jars in maven dependencies, and installed the eclipse plugin, but this deoesnt get you any closer to actually running a webservice with out the mystery configuration glue. CXF seems tied to spring, which is a big minus for us as we dont use spring (or need any of its features).

I noticed helios wtp has some kind of web service project called JSR-109. Is this java RPC only, or does it support the full SOAP websiervice system, and is it worth trying to figrue out?

Any advice very welcome. I must have googled 1000 pages in search of the web serive holy grail - i.e. how to create and deploy one to tomcat end to end. Is it supposed to be this hard?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

裸钻 2024-09-15 09:04:41

将此片段添加到您的 web.xml 文件中

<servlet>
    <servlet-name>wshello</servlet-name>
    <servlet-class>
        com.sun.xml.ws.transport.http.servlet.WSServlet
    </servlet-class>              
</servlet>      
<servlet-mapping>
    <servlet-name>wshello</servlet-name>
        <url-pattern>/webservice</url-pattern>
</servlet-mapping>

,然后创建一个名为 sun-jaxws.xml 的文件。

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

然后像往常一样创建一个war文件。您不需要 CXF 或 Axis 即可将基本 WebService 部署到 Tomcat 中。
顺便说一句,jax-ws 库 jars(jaxws-api.jar、jaxb-impl.jar 等)应该位于您的类路径中。您可以从此处下载jax-ws库

Add this fragment to your web.xml file

<servlet>
    <servlet-name>wshello</servlet-name>
    <servlet-class>
        com.sun.xml.ws.transport.http.servlet.WSServlet
    </servlet-class>              
</servlet>      
<servlet-mapping>
    <servlet-name>wshello</servlet-name>
        <url-pattern>/webservice</url-pattern>
</servlet-mapping>

And then just create a file whose name is sun-jaxws.xml.

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

Then create a war file as usual. You don't need CXF or Axis to deploy a basic WebService into Tomcat.
By the way jax-ws library jars( jaxws-api.jar, jaxb-impl.jar etc..) should be in your classpath. You can download jax-ws libraries from here

左岸枫 2024-09-15 09:04:41

我知道这是陈词滥调,但听起来你正试图重新发明轮子。出现 Axis2 和 CXF 之类的东西是有原因的。他们为你做了很多艰苦的工作。我使用过这两种方法并且取得了很大的成功。请记住,我的言论是基于有限的个人经验。

我发现 CXF 和 Spring 可以非常轻松地设置契约优先的 JAX-WS 服务,甚至添加 WS-Security、消息日志记录、模式验证和 HTTP 配置设置。大部分是通过 Spring XML 配置文件完成的。我还了解到 Spring 可以与 Quartz 一起使用来安排作业并管理数据访问。这是一个非常方便的工具。

Axis2,虽然我已经有一段时间没有使用它了,但我记得它让我可以轻松地将一些 POJO 转变为服务,并且花费最少的精力。

我对 Metro 的唯一体验是使用 NetBeans 创建的一个小测试服务,并在内置 Glassfish 服务器上运行它。这非常简单,但是 IDE 为您做了很多工作,这可能不是一个好的学习方式。感觉就像只需要点击几下鼠标,突然就有了一项服务。

另外这个问题是相关的。

祝你好运!

I know it's a cliche but it sounds like you are trying to reinvent the wheel. There's a reason there are things like Axis2 and CXF. They do a lot of the hard work for you. I've used both and had a lot of success with them. Keep in mind I'm speaking from limited personal experience.

I've found that CXF and Spring make it very easy to set up a contract-first JAX-WS service and even add WS-Security, message logging, schema validation and HTTP configuration settings. Mostly done with the Spring XML config file. I've also learned that Spring can be used with Quartz to schedule jobs and manage your data access as well. It's a pretty handy tool.

Axis2, while I haven't used it in a while, I remember it making it pretty easy to turn some POJOs into a service with minimal effort.

My only experience with Metro is a little test service I created with NetBeans and ran it on the built-in Glassfish server. It was very easy, but the IDE did a lot of the work for you, which probably isn't a good way to learn. It felt like it just took a bunch of mouse clicks and all of a sudden there was a service.

Also this question is kind of related.

Good luck!

萌面超妹 2024-09-15 09:04:41

看看 https://glenmazza.net/blog/entry/web-service-教程。这是 CXF 和 Metro 的完整分步指南。 Tomcat 用于部署,还有 Maven 和 ant 版本,以防您更喜欢其中一种来组织项目构建。

Take a look at https://glenmazza.net/blog/entry/web-service-tutorial. It is a complete step by step guide for CXF and metro. Tomcat is used for deployment and there are also maven and ant versions in case you prefer one to another option for organizing project builds.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文