运行 java wsdl 客户端时找不到主类错误 [英] Could not find main class error when running a java wsdl client

查看:32
本文介绍了运行 java wsdl 客户端时找不到主类错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了以下代码,它是用于 http 的客户端 wsdl://www.nanonull.com/TimeService/TimeService.asmx?WSDL:

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

但是当我尝试使用 java 运行它时,我得到以下信息:

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?

推荐答案

您编写的主类是 time.Client,但您正在尝试运行 client.Client.最好这样运行:

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

java time.Client

如果这没有帮助,那么您有一个类路径问题 - java 在类路径中找不到主类.使用 -classpath 设置类路径 选项:

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

这篇关于运行 java wsdl 客户端时找不到主类错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆