Friday, June 28, 2013

Simplest JAX-WS in Eclipse

1. Create a new java project in Eclipse

2. Create package structure com.mycompany.wsServer

3. Create following class in it.
SimpleWebService.java
package com.mycompany.wsServer;
import javax.jws.WebService;

@WebService
public class SimpleWebService {
    public String getGreeting() {
        return "Hello ";
    }
}


4. Create ant build file
build.xml
<project default="wsgen">
 <target name="wsgen" >
   <exec executable="wsgen">    
    <arg line="-cp ./bin -keep -s ./src -d ./bin com.mycompany.wsServer.SimpleWebService"/>    
   </exec>    
 </target>
</project>


5. Run the Ant build.xml file. Generated code is found under the new package called com.mycompany.wsServer.jaxws

6. Create following class to run the web service
RunService.java
package com.mycompany.wsServer;
import javax.xml.ws.Endpoint;


public class RunService {
     public static void main(String[] args) {
        System.out.println("Web Service started.");
        Endpoint.publish("http://localhost:8080/wsServerExample", new SimpleWebService());
      }
}


7. Run the class. Web service will start. View the wsdl on
 http://localhost:8080/wsServerExample?wsdl

No comments:

Post a Comment