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

谁说我不能喝 提交于 2019-12-12 04:38:22

问题


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?


回答1:


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



回答2:


You need to set the classpath:

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


来源:https://stackoverflow.com/questions/4007938/could-not-find-main-class-error-when-running-a-java-wsdl-client

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!