简体   繁体   中英

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

I have written the following code, which is meant to be a client wsdl for http://www.nanonull.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

您需要设置类路径:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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