开发者

Could not find main class error when running a java wsdl client

开发者 https://www.devze.com 2023-01-21 12:36 出处:网络
I have written the following code, which is meant to be a client wsdl for http://www.nanonull开发者_如何学Python.com/TimeService/TimeService.asmx?WSDL:

I have written the following code, which is meant to be a client wsdl for http://www.nanonull开发者_如何学Python.com/TimeService/TimeService.asmx?WSDL:

package time;
class Client {
 public static void main(String args[]){
        TimeService service = new TimeService();
        TimeServiceSoap port= service.getTimeServiceSoap();
        String result = port.getTimeZoneTime("UTC+10");
        System.out.println("Time is "+result);
 }
}

But when I try to run it with java I get the following:

C:\Program Files\Java\jdk1.6.0_22\bin>java client.Client
Exception in thread "main" java.lang.NoClassDefFoundError: client/Client
Caused by: java.lang.ClassNotFoundException: client.Client
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: client.Client.  Program will exit.

Does this error mean I should be importing any classes?


The main class you wrote is time.Client, but you are trying to run client.Client. Better run it like this:

java time.Client

If this does not help, then you have a classpath problem - java cannot find the main class in the classpath. Set the classpath with -classpath option:

java -classpath classes-directory;list-of-jar-files time.Client


You need to set the classpath:

C:\Program Files\Java\jdk1.6.0_22\bin>java -cp . client.Client
0

精彩评论

暂无评论...
验证码 换一张
取 消