我想使用Java创建和发布简单的WebService。
一切都会编译。
当我跑步
> java -cp。 ts.TimeServerPublisher
我遇到错误
错误:找不到或加载主类ts.TimeServerPublisher
知道为什么会有问题吗?
我的代码如下
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();
}
最佳答案
您尝试运行的类在ts包中。
因此,如果您有以下文件树:
/bin/ts/TimeServerPublisher
您必须运行以下命令
java -cp /bin ts/TimeServerPublisher
关于java - 编译后无法执行Java代码,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7946721/