我有下一个问题。我在Windows中使用MinGW。这里java很棒。我试图在debian中运行java程序并得到不可预知的结果。这是我的代码:
import java.io.IOException;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;
public class FTPConnectAndLoginDemo {
public static void main(String[] args) {
String server = "192.168.253.130";
int port = 21;
String user = "ovod88";
String pass = "taon88";
FTPClient ftpClient = new FTPClient();
try {
ftpClient.connect(server, port);
showServerReply(ftpClient);
// int replyCode = ftpClient.getReplyCode();
// if (!FTPReply.isPositiveCompletion(replyCode)) {
// System.out.println("Operation failed. Server reply code: " + replyCode);
// return;
// }
// boolean success = ftpClient.login(user, pass);
// showServerReply(ftpClient);
// if (!success) {
// System.out.println("Could not login to the server");
// return;
// } else {
// System.out.println("LOGGED IN SERVER");
// }
} catch (IOException ex) {
System.out.println("Oops! Something wrong happened");
ex.printStackTrace();
}
}
private static void showServerReply(FTPClient ftpClient) {
String[] replies = ftpClient.getReplyStrings();
if (replies != null && replies.length > 0) {
for (String aReply : replies) {
System.out.println("SERVER: " + aReply);
}
}
}
}
这个程序编译成这样(需要jar在我的主目录中):
javac -cp /home/ovod88/commons-net-3.1.jar FTPConnectAndLoginDemo.java
但它没有运行((我在这个站点和许多其他解决方案中找到了,比如添加-classpath。或-cp。来运行命令,如:
java -cp /home/ovod88/commons-net-3.1.jar FTPConnectAndLoginDemo
或
java -cp . FTPConnectAndLoginDemo
或
java -classpath . FTPConnectAndLoginDemo
无效(((它的组合也没有用)((错误是:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/net/ftp/FTPClient
at FTPConnectAndLoginDemo.main(FTPConnectAndLoginDemo.java:11)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.net.ftp.FTPClient
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
... 1 more