Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to deploy a jax-ws service to eclipse or 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?

like image 420
wingnut Avatar asked Jul 08 '10 18:07

wingnut


People also ask

How do I add JAX-WS to eclipse?

Right-click the project, select Properties, select Java Build Path, and click the Libraries tab. Click Add Library, select MyEclipse Libraries, and click Next. Scroll down, and select the JAX-WS library container to be added to your project's build path, and click Finish. Click OK to close the Properties window.

Does Tomcat support SOAP?

In this example, the Eclipse Java EE IDE is used to create a new Java SOAP service. The Apache Tomcat web server is used to deploy and run the Java SOAP service and SOAP-UI is used to test the service operations.


1 Answers

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

like image 144
azizunsal Avatar answered Sep 20 '22 02:09

azizunsal