Hello. I am newbe Java programmer, as I have wrote my first java application two days ago, so be tolerant. I am using NetBeans IDE 6.7.1. I am writting small application, which is to connect with FTP server, and as a first step, it displays names of the files at the server. For this purpose I am using not standard library from Apache : commons-net-ftp-2.0.jar. This library has been installed properly. It is visible in NetBeans in Libraries section of teh project. Everything works fine.
When I bulid Main Project, the file myfile.jar is build in folder "dist". When I try to run application by Run Main Project, everything works OK (I can connect to teh server and show the names of files.)
This is my code:
|
Code:
|
package ftpupload;
import java.io.File;
import org.apache.commons.net.ftp.FTPClient;
public class Main {
public static void main(String[] args) {
int i=0;
try{
FTPClient fcl= new FTPClient();
fcl.connect("ftp.nazwaserwera.pl");
fcl.login("user", "password");
String[] files = fcl.listNames();
System.out.println(fcl.getStatus());
while(i<files.length){
System.out.println(files[i]);
i++;
}
fcl.logout();
}
catch (Exception E) {
System.err.println(E.getMessage());
}
}
} |
The problem apperas when I want to run this app in console outside NetBeans IDE.
When I put(in the "dist" folder of the project): java -jar myfile.jar
I get this message:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/ne
t/ftp/FTPClient
Caused by: java.lang.ClassNotFoundException: org.apache.commons.net.ftp.FTPClien
t
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: ftpupload.Main. Program will exit.
My main question:
1.Can You tell me where the problem is ??
I also wonder about some other things:
2. Do I have to add manually not standard, as it works fine in NetBeans but not on the console ??
3. How can I add this not standart library, so it will be possible to run this app on the machine, where this library is not installed ( only JVM present ).
Thanks in advance, and sory for my english.
Best regards from Poland.