Search code examples
eclipsetomcatjax-ws

JAX-WS Web Services and Eclipse Dynamic Web Project


I saw several tutorials on the web about creating web services, but If I look at the Eclipse Dynamic Web Project structure it seems to me that there should be a kind of "build-in" way to create those web services

enter image description here

So, is there a tutorial specific for adding web services to an existing Dynamic Web Project and that will end up showing them under JAX-WS Web Services folder (indicated by the arrow in the image above)? Thanks!


Solution

  • Those should be populated if the module contains a JAX-WS web service.

    To see an item show up under Service Endpoint Interfaces, create a Java interface which is annotated with javax.jws.WebService:

    package org.example.sampleservice;
    
    import javax.jws.WebMethod;
    import javax.jws.WebService;
    
    @WebService
    public interface SampleService {
    
        @WebMethod
        String sayHello(String name);
    }
    

    Produces:

    populated Service Endpoint Interface in eclipse 4.4

    To populate the Web Services tree, create a web service implementation class. Note this example implements the service endpoint interface; this is not a technical requirement. In other words, you can populate one and not the other. Only this step will actually produce a functional web service implementation within the module (and the eclipse UI you mention):

    package org.example.sampleservice;
    
    import javax.annotation.Resource;
    import javax.jws.HandlerChain;
    import javax.jws.WebService;
    import javax.xml.ws.WebServiceContext;
    
    @WebService(endpointInterface = "org.example.sampleservice.SampleService")
    @HandlerChain(file="handlers.xml")
    public class SampleServiceImpl implements SampleService {
    
        @Override
        public String sayHello(String name) {
            return "Hello, " + name;
        }
    
    }
    

    populated eclipse Web Services tree