I want to create and publish simple WebService using Java.
Everything compiles.
When I run
>java -cp . ts.TimeServerPublisher
I am getting error
Error: Could not find or load main class ts.TimeServerPublisher
Any idea why it is a problem?
My code looks like following
TimeServerPublisher
package ts;
import javax.xml.ws.Endpoint;
public class TimeServerPublisher {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Endpoint.publish("http://127.0.0.1:9876/ts", new TimeServerImpl());
}
}
TimeServerImpl.java
package ts;
import java.util.Date;
import javax.jws.WebService;
@WebService(endpointInterface = "ts.TimeServer")
public class TimeServerImpl implements TimeServer {
public String getTimeAsString() { return new Date().toString(); }
public long getTimeAsElapsed() { return new Date().getTime(); }
}
TimeServer.java
package ts;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
@WebService
@SOAPBinding(style = Style.RPC)
public interface TimeServer {
@WebMethod String getTimeAsString();
@WebMethod long getTimeAsElapsed();
}
The class you are tryin to run is in the package ts.
So if you have this file tree:
You have to run the following command