Results 1 to 6 of 6
  1. #1
    Natalia is offline Member
    Join Date
    Nov 2010
    Posts
    3
    Rep Power
    0

    Default Running Java program

    I have a program which uses an external library, apfloat.jar.
    It compiles and runs in eclipse IDE, but I need to be able to compile and run it from the terminal.

    It actually compiles from the terminal when I use the following command:
    Java Code:
    javac Generator.java -classpath apfloat.jar
    but then I have no idea how to run it, when I use this:

    Java Code:
    java Generator -classpath apfloat.jar
    I'm getting the following exception:
    Java Code:
    Exception in thread "main" java.lang.NoClassDefFoundError: org/apfloat/Apfloat
    Caused by: java.lang.ClassNotFoundException: org.apfloat.Apfloat
            at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    Could you maybe tell me how can I run this program?

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Form the directory containing Generator.class and apfloat.jar try changing the order of the arguments:

    Java Code:
    java -classpath apfloat.jar Generator

  3. #3
    Natalia is offline Member
    Join Date
    Nov 2010
    Posts
    3
    Rep Power
    0

    Default

    I tried it, and now it doesn't find the class "Generator" (and clearly the class is there):

    Java Code:
    nataliazon$ ls
    Generator.class Generator.java  apfloat.jar     lib             org
    nataliazon$
    nataliazon$ java -cp apfloat.jar Generator
    Exception in thread "main" java.lang.NoClassDefFoundError: Generator
    Caused by: java.lang.ClassNotFoundException: Generator
            at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Sorry, I wasn't thinking (more coffee needed).

    You also have to tell the java executable that the current directory is part of the classpath.

    Java Code:
    java -cp .:apfloat.jar Generator

    "dash c p space dot colon etc"

  5. #5
    Natalia is offline Member
    Join Date
    Nov 2010
    Posts
    3
    Rep Power
    0

    Default

    It's working now! Big thanks!

  6. #6
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

Similar Threads

  1. Running a Java Program
    By Valkyrie in forum New To Java
    Replies: 13
    Last Post: 11-05-2009, 03:43 AM
  2. Error running java program using URL
    By gio123bg in forum New To Java
    Replies: 6
    Last Post: 06-30-2009, 06:26 PM
  3. error running java program
    By bdasilva in forum New To Java
    Replies: 1
    Last Post: 06-29-2009, 01:46 AM
  4. Replies: 1
    Last Post: 01-12-2009, 08:59 AM
  5. [SOLVED] opening/running a program from java
    By xcallmejudasx in forum New To Java
    Replies: 3
    Last Post: 11-25-2008, 08:12 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
  •