当前位置: 技术问答>java相关
请大家看看下面这段程序的错误!
来源: 互联网 发布时间:2015-04-16
本文导语: 我是用命令行方式执行的 javac JabberServer.java 没问题 java JabberServer 报错了Exception in thread "main" java.lang.noclassdeffounderror:JabberSerber 这是为什么啊? 程序如下 package socket; import java.io.*; import java.net.*; public class...
我是用命令行方式执行的
javac JabberServer.java 没问题
java JabberServer
报错了Exception in thread "main" java.lang.noclassdeffounderror:JabberSerber
这是为什么啊?
程序如下
package socket;
import java.io.*;
import java.net.*;
public class JabberServer {
// Choose a port outside of the range 1-1024:
public static final int PORT = 8080;
public static void main(String[] args)
throws IOException {
ServerSocket s = new ServerSocket(PORT);
System.out.println("Started: " + s);
try {
// Blocks until a connection occurs:
Socket socket = s.accept();
try {
System.out.println(
"Connection accepted: "+ socket);
BufferedReader in =
new BufferedReader(
new InputStreamReader(
socket.getInputStream()));
// Output is automatically flushed
// by PrintWriter:
PrintWriter out =
new PrintWriter(
new BufferedWriter(
new OutputStreamWriter(
socket.getOutputStream())),true);
while (true) {
String str = in.readLine();
if (str.equals("END")) break;
System.out.println("Echoing: " + str);
out.println(str);
}
// Always close the two sockets...
} finally {
System.out.println("closing...");
socket.close();
}
} finally {
s.close();
}
}
} ///:~
javac JabberServer.java 没问题
java JabberServer
报错了Exception in thread "main" java.lang.noclassdeffounderror:JabberSerber
这是为什么啊?
程序如下
package socket;
import java.io.*;
import java.net.*;
public class JabberServer {
// Choose a port outside of the range 1-1024:
public static final int PORT = 8080;
public static void main(String[] args)
throws IOException {
ServerSocket s = new ServerSocket(PORT);
System.out.println("Started: " + s);
try {
// Blocks until a connection occurs:
Socket socket = s.accept();
try {
System.out.println(
"Connection accepted: "+ socket);
BufferedReader in =
new BufferedReader(
new InputStreamReader(
socket.getInputStream()));
// Output is automatically flushed
// by PrintWriter:
PrintWriter out =
new PrintWriter(
new BufferedWriter(
new OutputStreamWriter(
socket.getOutputStream())),true);
while (true) {
String str = in.readLine();
if (str.equals("END")) break;
System.out.println("Echoing: " + str);
out.println(str);
}
// Always close the two sockets...
} finally {
System.out.println("closing...");
socket.close();
}
} finally {
s.close();
}
}
} ///:~
|
应该是在与socket的同级目录中运行
java socket.JabberServer
java socket.JabberServer
|
你可以把JabberServer.class放在当前目录下socket子目录下。然后使用命令来运行:
java socket.JabberServer
我试过你的代码,运行成功。
java socket.JabberServer
我试过你的代码,运行成功。
|
肯定不对,既然是package socket,就应该是java socket.JabbeServer
|
将 环境变量中classpath加入".;"试一下
|
try
java -classpath .;%classpath% JabberServer
or add ".;" to your CLASSPATH environment varialbe in Start->Settings->Control Panel->System->Advanced tab
or in your c:autoexec.bat
java -classpath .;%classpath% JabberServer
or add ".;" to your CLASSPATH environment varialbe in Start->Settings->Control Panel->System->Advanced tab
or in your c:autoexec.bat
|
楼上对
|
先运行命令:set classpath=%classpath%;.
然后在当前目录下建立文件夹socket
把你编译好的classA文件copy到socket下
用java socket.JabberServer 命令就可以运行了
然后在当前目录下建立文件夹socket
把你编译好的classA文件copy到socket下
用java socket.JabberServer 命令就可以运行了
|
你也可以在classpath中加入 classpath=.;.代表当前目录!
然后到socket目录下执行java JabberServer就可以了
然后到socket目录下执行java JabberServer就可以了