how to deploy a jax-ws service to eclipse or tomcat?

£可爱£侵袭症+ 提交于 2020-01-11 05:37:09

问题


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?


回答1:


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




回答2:


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!




回答3:


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.



来源:https://stackoverflow.com/questions/3206681/how-to-deploy-a-jax-ws-service-to-eclipse-or-tomcat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!