繁体   English   中英

wsimport的可执行Web服务客户端时出现Java异常

[英]java exception when executable web service client by wsimport

我正在关注本教程

我创建了这个简单的Web服务

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

我对Web服务非常陌生的解决方案是什么

编辑后

在此处输入图片说明

在您的环境变量中,确保jdk bin文件夹在路径中。 请遵循以下指示信息: http : //java.com/en/download/help/path.xml

该文件夹将类似于C:\\ Program Files \\ java \\ jdk1.7.0_09 \\ bin

您可以通过打开新的命令提示符窗口并键入java -version如果java -version则bin文件夹位于您的路径上。

还要检查javac -version也可以使用。 如果第一个成功,但这个没有成功,则可能意味着您的路径上有一个JRE,而不是JDK。


请执行下列操作:

  1. 在Eclipse Window->Preferences->Installed JREs ,找到您已在此处安装的JDK。
  2. 打开环境属性(在我的计算机上单击右键->属性->高级,然后单击环境变量)。
  3. 在系统变量中,找到路径变量,然后单击“编辑”。
  4. 注意,此路径变量是用半冒号分隔的文件夹列表。 查找现有的Java并将其删除。 然后将在步骤1中在Eclipse中找到的JDK的位置附加到末尾,后跟/ bin。

例如mypathvar; C:\\ Program Files \\ Java \\ jdk1.6.0_37 \\ bin

单击“确定”,然后打开一个新的命令提示符,然后键入javac -version ,它现在应该可以使用,但是您需要打开一个新的命令提示符。 如果它不起作用谷歌如何将Java添加到我的路径变量。

如果您无法在Eclipse中找到JDK,则可以随时下载一个(Google“下载JDK”)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM