Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
12.7k views
in Java FTP by (300 points)
I am getting this error when trying to run my test program:
[root@tux tmp]# java testit
Exception in thread "main" java.lang.NoClassDefFoundError: com/enterprisedt/net/ftp/FTPClient

this is how im compiling it and it does this fine:
[root@tux tmp]# javac -classpath /tmp/edtftpj-1.4.1/edtftpj-1.4.1.jar testit.java

here is my code:

import com.enterprisedt.net.ftp.*;
import com.enterprisedt.net.ftp.FTPException;
import com.enterprisedt.net.ftp.FTPClient;
import com.enterprisedt.net.ftp.FTPTransferType;
import com.enterprisedt.net.ftp.FTPConnectMode;
import java.io.*;
import java.util.*;
import java.lang.*;
import java.net.*;

public class testit {
public void main(String[] args) {
System.out.println("Setting Variables");
String host = "xxx.xxx.xxx.xxx";
String user = "xxx";
String password = "xxx";
String filename = "dead.letter";
String directory = "/home/xxx";

try {
FTPClient ftp = new FTPClient(host, 21);
ftp.login(user, password);
ftp.setType(FTPTransferType.BINARY);
System.out.println("Binary mode set");
ftp.setConnectMode(FTPConnectMode.PASV);
System.out.println("Connection mode set to PASV");
ftp.chdir(directory);
byte[] buf = ftp.get(filename);
System.out.println("Got " + buf.length + " bytes");
ftp.quit();
} catch (IOException ex) {
System.out.println("Caught exception: " + ex.getMessage());
}
catch (Exception ex) {
}
}
}


does anyone have any clue why it compiles but does not find the classes at run time.

7 Answers

0 votes
by (161k points)
Put the jar file in the classpath when you run it

I am getting this error when trying to run my test program:
[root@tux tmp]# java testit
Exception in thread "main" java.lang.NoClassDefFoundError: com/enterprisedt/net/ftp/FTPClient

this is how im compiling it and it does this fine:
[root@tux tmp]# javac -classpath /tmp/edtftpj-1.4.1/edtftpj-1.4.1.jar testit.java

does anyone have any clue why it compiles but does not find the classes at run time.
0 votes
by (300 points)
[root@tux /]# java -classpath /usr/java/j2sdk1.4.2_04/jre/lib/edtftpj-1.4.1.jar testit
Exception in thread "main" java.lang.NoClassDefFoundError: testit
0 votes
by (300 points)
it does load the class files in not sure why it does not run
0 votes
by (161k points)
testit must also be in the classpath

it does load the class files in not sure why it does not run
0 votes
by (300 points)
if testit is in the root dir and im in the root dir and i do
java -cp /usr/java/j2sdk1.4.2_04/jre/lib/edtftpj-1.4.1.jar testit
is that not the same maybe you could tell me how you would do it.
i don't have these problems when sourcing in other stuff like servlet stuff doing it this way.
0 votes
by (161k points)
Your classpath is set to /usr/java/j2sdk1.4.2_04/jre/lib/edtftpj-1.4.1.jar.

testit is not in this jar, therefore it will not be found.

You need to add to the classpath the directory in which the testit.class is found, e.g. "." for the current directory.

http://java.sun.com/j2se/1.4.2/docs/too ... #userclass

if testit is in the root dir and im in the root dir and i do
java -cp /usr/java/j2sdk1.4.2_04/jre/lib/edtftpj-1.4.1.jar testit
is that not the same maybe you could tell me how you would do it.
i don't have these problems when sourcing in other stuff like servlet stuff doing it this way.
0 votes
by (300 points)
thanks bud your the man

Categories

...