我编写了以下代码,它是http://www.nanonull.com/TimeService/TimeService.asmx?WSDL的客户端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);
}
}
但是当我尝试用java运行它时,我得到以下结果:
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.
这个错误是否意味着我应该导入任何类?
答案 0 :(得分:2)
您编写的主要课程是time.Client
,但您尝试运行client.Client
。更好地运行它:
java time.Client
如果这没有帮助,那么你有一个类路径问题 - java无法在类路径中找到主类。使用-classpath
option设置类路径:
java -classpath classes-directory;list-of-jar-files time.Client
答案 1 :(得分:1)
您需要设置类路径:
C:\Program Files\Java\jdk1.6.0_22\bin>java -cp . client.Client