Marco Dinatsoli
Marco Dinatsoli

Reputation: 10580

java exception when executable web service client by wsimport

I am following This Tutorial

I created this simple web service

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;
    }
}

and this simple server :

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");
    }
}

and when I test to get the WSDL, it works good and I get this xml result:

<?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>

but when I tried to create a web service client like this:

<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>

I got this exception when running that client:

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

what is the solution I am very new to web service

after an edit

enter image description here

Upvotes: 0

Views: 3639

Answers (1)

cowls
cowls

Reputation: 24344

In your environment variables make sure the jdk bin folder is on your path. Follow these instructions: http://java.com/en/download/help/path.xml

The folder will be something like C:\Program Files\java\jdk1.7.0_09\bin

You can test by opening a NEW command prompt window and typing java -version if this works then the bin folder is on your path.

Also check that javac -version also works. If it the first works but this one doesnt it probably means you have a JRE on your path instead of a JDK.


Do the following:

  1. In Eclipse Window->Preferences->Installed JREs, find the JDK you have installed here.
  2. Open environment properties (Right cick on my computer -> properties -> Advanced then click environment variables).
  3. In system variables find the path variable and click edit.
  4. Note, this path variable is a semi colon separated list of folders. Find the existing one for Java and delete it. Then append to the end the location of your JDK as found in Eclipse in step 1 followed by /bin.

e.g. mypathvar;C:\Program Files\Java\jdk1.6.0_37\bin

hit ok then open a new command prompt and type javac -version, it should work now but you will need to open a NEW command prompt. If it doesnt work google how to add java to my path variable.

If you cant find a JDK in eclipse you can always download one (google "download JDK")

Upvotes: 1

Related Questions