我試圖在eclipse中創建一個簡單的Web服務。首先,我創建了一個空的java項目和src文件夾中在Eclipse中創建簡單的JAX-WS WebService
- 加入下列三個文件Greeting.java
package com.alfaisaliah;
import javax.jws.WebService;
import javax.jws.WebMethod;
@WebService
public interface Greeting {
@WebMethod
String sayHello(String name);
}
- GreetingImp.java
- WSPublisher
package com.alfaisaliah;
import javax.jws.WebService;
@WebService(endpointInterface="com.alfaisaliah.Greeting")
public class GreetingImp implements Greeting {
@Override
public String sayHello(String name) {
return "Hello " + name;
}
}
package com.alfaisaliah;
import javax.xml.ws.Endpoint;
public class WSPublisher {
public static void main(String[] args){
Endpoint.publish("http://localhost:8081/WS/Greeting", new GreetingImp());
}
}
我遵循的教程沒有指定任何服務器來運行Web服務!我想知道是否需要指定任何服務器。我已經有了Tomcat v5.5,但在本例中沒有使用它。每當我將這個項目作爲一個java項目運行時,我都會遇到某種錯誤。任何人都可以請幫助我確定我的問題在哪裏試圖運行Web服務。這裏是Eclipse控制檯
Feb 26, 2012 12:01:00 PM com.sun.xml.internal.ws.model.RuntimeModeler getRequestWrapperClass
INFO: Dynamically creating request wrapper Class com.alfaisaliah.jaxws.SayHello
Feb 26, 2012 12:01:00 PM com.sun.xml.internal.ws.model.RuntimeModeler getResponseWrapperClass
INFO: Dynamically creating response wrapper bean Class com.alfaisaliah.jaxws.SayHelloResponse
同樣的輸出,當我再次運行該項目它說,該地址已在使用
Feb 26, 2012 12:01:00 PM com.sun.xml.internal.ws.model.RuntimeModeler getRequestWrapperClass
INFO: Dynamically creating request wrapper Class com.alfaisaliah.jaxws.SayHello
Feb 26, 2012 12:01:00 PM com.sun.xml.internal.ws.model.RuntimeModeler getResponseWrapperClass
INFO: Dynamically creating response wrapper bean Class com.alfaisaliah.jaxws.SayHelloResponse
Exception in thread "main" com.sun.xml.internal.ws.server.ServerRtException: Server Runtime Error: java.net.BindException: Address already in use
我會感激你的幫助球員:)
關於創建包裝bean的消息是OK的。它基本上是JAX-WS即時生成WSDL的能力的一部分。 – 2012-02-27 15:54:32