Results 1 to 2 of 2
  1. #1
    metoda is offline Member
    Join Date
    Nov 2009
    Posts
    7
    Rep Power
    0

    Unhappy small FTP app, commons-net-ftp, problems with run

    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:
    Java 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.

  2. #2
    sky
    sky is offline Member
    Join Date
    Nov 2009
    Posts
    96
    Rep Power
    0

    Default

    I'm just guessing, but maybe the library is only installed for NetBeans and it is not in the PATH of your operating system. So search in Google how to add non-standard librarys to Java.

Similar Threads

  1. Replies: 0
    Last Post: 06-16-2009, 04:35 PM
  2. Replies: 0
    Last Post: 09-13-2008, 08:58 PM
  3. Problems with ftp, commons library
    By jurka in forum Networking
    Replies: 0
    Last Post: 09-01-2008, 06:46 PM
  4. Commons Library Framework 0.8.0
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 10-02-2007, 05:13 PM
  5. Commons validator
    By aczuczor in forum Web Frameworks
    Replies: 0
    Last Post: 07-27-2007, 09:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •