我正在关注本教程
我创建了这个简单的网络服务
package com.examples.services;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService
public class HelloWeb {
@WebMethod
public String sayHi(String name) {
return "Hi " + name;
}
}
和这个简单的服务器:
package com.examples.services;
import javax.xml.ws.Endpoint;
public class Server {
public static void main(String args[]) {
Endpoint.publish("http://localhost:9898/HelloWeb", new HelloWeb());
System.out.println("here we go");
}
}
当我测试获取 WSDL 时,它运行良好,我得到了这个 xml 结果:
<?xml version="1.0" encoding="UTF-8" ?>
- <!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6.
-->
- <!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6.
-->
- <definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://services.examples.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://services.examples.com/" name="HelloWebService">
- <types>
- <xsd:schema>
<xsd:import namespace="http://services.examples.com/" schemaLocation="http://localhost:9898/HelloWeb?xsd=1" />
</xsd:schema>
</types>
- <message name="sayHi">
<part name="parameters" element="tns:sayHi" />
</message>
- <message name="sayHiResponse">
<part name="parameters" element="tns:sayHiResponse" />
</message>
- <portType name="HelloWeb">
- <operation name="sayHi">
<input message="tns:sayHi" />
<output message="tns:sayHiResponse" />
</operation>
</portType>
- <binding name="HelloWebPortBinding" type="tns:HelloWeb">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
- <operation name="sayHi">
<soap:operation soapAction="" />
- <input>
<soap:body use="literal" />
</input>
- <output>
<soap:body use="literal" />
</output>
</operation>
</binding>
- <service name="HelloWebService">
- <port name="HelloWebPort" binding="tns:HelloWebPortBinding">
<soap:address location="http://localhost:9898/HelloWeb" />
</port>
</service>
</definitions>
但是当我尝试创建这样的 Web 服务客户端时:
<project name="My Web Service Build" default="wsimport">
<target name="wsimport">
<exec executable="wsimport">
<arg line="-keep -s ./src -p com.examples.services.client http://localhost:9898/HelloWeb?wsdl"/>
</exec>
</target>
</project>
运行该客户端时出现此异常:
Buildfile: C:\Users\User\workspace\MyWebService\wsbuild.xml
wsimport:
BUILD FAILED
C:\Users\User\workspace\MyWebService\wsbuild.xml:5: Execute failed: java.io.IOException: Cannot run program "wsimport": CreateProcess error=2, The system cannot find the file specified
Total time: 646 milliseconds
什么是解决方案我对网络服务很陌生