package gt3tutorial.core.first.client; import gt3tutorial.core.first.Math.MathServiceLocator; import gt3tutorial.core.first.Math.MathPortType; import java.net.URL; public class MathClient { public static void main(String[] args) { try { // Get command-line arguments int a = Integer.parseInt(args[1]);//控制台输入的参数2 int b = Integer.parseInt(args[2]);//控制台输入的参数3 URL GSH = new java.net.URL(args[0]); //控制台输入的参数0,获得服务句柄 // Get a reference to the remote web service MathServiceLocator mathService = new MathServiceLocator(); MathPortType math = mathService.getMathService(GSH); // Call remote method 'add' int sum = math.add(a,b); // Print result System.out.println(a + " + " + b + " = " + sum); }catch(Exception e) { System.out.println("ERROR!"); e.printStackTrace(); } } }
我加了啊,怎么还是不行啊?
编译好的class文件也在D:\gt3test\gt3tutorial\core\first分别为:
D:\gt3test\gt3tutorial\core\first\MathClient.java
D:\gt3test\gt3tutorial\core\first\MathClient.class我运行:
D:\gt3test\gt3tutorial\core\first>java MathClient
就出现:
Exception in thread "main" java.lang.NoClassDefFoundError: MathClient
CLASSPATH=.;D:\j2sdk1.4.2\bin;D:\j2sdk1.4.2\lib\tools.jar;D:\j2sdk1.4.2\lib\axis
.jar;D:\grid\ogsa\lib\ogsa.jar;D:\gt3test;D:\grid\ogsa\lib\jaxrpc.jar;D:\gt3test
\gt3tutorial\core\first;D:\j2sdk1.4.2\jre\bin;D:\j2sdk1.4.2\jre\lib怎么还是不行啊?
import gt3tutorial.core.first.Math.MathServiceLocator;
import gt3tutorial.core.first.Math.MathPortType;
import java.net.URL;
public class MathClient
{
public static void main(String[] args)
{
try
{
// Get command-line arguments
int a = Integer.parseInt(args[1]);//控制台输入的参数2
int b = Integer.parseInt(args[2]);//控制台输入的参数3
URL GSH = new java.net.URL(args[0]); //控制台输入的参数0,获得服务句柄
// Get a reference to the remote web service
MathServiceLocator mathService = new MathServiceLocator();
MathPortType math = mathService.getMathService(GSH);
// Call remote method 'add'
int sum = math.add(a,b);
// Print result
System.out.println(a + " + " + b + " = " + sum);
}catch(Exception e)
{
System.out.println("ERROR!");
e.printStackTrace();
}
}
}
你的java命令写错了,应该类包含在包中,在命令行中先退到D:\gt3test\目录下,然后执行java gt3tutorial.core.first.client.MathClient 命令
改为:
你的java命令写错了,类包含在包中,执行时要写完整的路径名.在命令行中先退到D:\gt3test\目录下,然后执行java gt3tutorial.core.first.client.MathClient 命令
或
D:\gt3test>set classpath=D:\gt3test;%classpath%
然后
D:\gt3test>java gt3tutorial.core.first.MathClient