Trouble Adding .jar to classpath

Discussion in 'Java' started by zhacker, Feb 1, 2012.

  1. zhacker

    zhacker New Member

    Feb 1, 2012
    Likes Received:
    Trophy Points:
    Hi everyone,

    I have been programming in java for a while but I haven't used external .jar archives previously. Now, I am faced with the current situation:

    1- I have a java file ( located in my /home directory.
    2- Under: /home/lib/ I have two .jar archives, namely: commons-math-1.2.jar and weka.jar
    3- In the sourcecode (, I have the following import statements:

    import weka.core.Utils;

    import org.apache.commons.math.distribution.ChiSquaredDistribution;
    import org.apache.commons.math.distribution.ChiSquaredDistributionImpl;


    my weka.jar has the structure: weka/core/Utils.class
    my commons-math-1.2.jar contains the structure: /org/apache/commons/math/distribution/ChiSquaredDistribution.class and ChiSquaredDistributionImpl.class - However, notice the name of the .jar archive - unlike my weka.jar, commons-math-1.2 does not show up in the import statement.

    Now, when I compile using the following:

    javac -cp ".:lib/weka.jar:lib/commons-math-1.2.jar" it outputs the following:

    [zibrahimbrc@bignode lib]$ javac -cp ".:lib/weka.jar:lib/commons-math-1.2.jar"
    javac: file not found:
    Usage: javac <options> <source files>
    use -help for a list of possible options

    Which I am assuming it's okay. However, the following exception is generated when I run the corresponding .class file:

    [zibrahimbrc@bignode snp_harvester]$ java SNPHarvester
    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/math/distribution/ChiSquaredDistribution
    Caused by: java.lang.ClassNotFoundException: org.apache.commons.math.distribution.ChiSquaredDistribution
    at Method)
    at java.lang.ClassLoader.loadClass(
    at sun.misc.Launcher$AppClassLoader.loadClass(
    at java.lang.ClassLoader.loadClass(
    Could not find the main class: SNPHarvester. Program will exit.

    It's not finding the classes in commons-math-1.2.jar

    Any ideas about what I'm doing wrong? your help is highly appreciated. Thank you very much in advance.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice