tags:

views:

259

answers:

1

Hello,

I am trying to use Jama package in my code in Linux. In my Main class, I am trying to use Matrix class.

Here is my Main class:

import Jama.*;
class Main {
    public static void main(String[] args) {
        Matrix A = new Matrix(3,5);
    }
}

I am not using any IDE, my makefile is:

JC = javac -classpath $(CLASSPATH):jars/Jama-1.0.2.jar
.SUFFIXES: .java .class
.java.class:
    $(JC) $(JFLAGS) $*.java

CLASSES = \
    Title.java \
    Sentence.java \
    Document.java \
    LSA.java \
    Main.java \

default: classes

classes: $(CLASSES:.java=.class)

clean:
    $(RM) *.class

My jar file is under ./jars/ directory

And I have the following output when I run Main

sefa@sefa-laptop:~/Desktop/courses/cs578-nlp/CS578Project/source$ java Main 
Exception in thread "main" java.lang.NoClassDefFoundError: Jama/Matrix
    at Main.main(Main.java:9)
Caused by: java.lang.ClassNotFoundException: Jama.Matrix
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
    ... 1 more
sefa@sefa-laptop:~/Desktop/courses/cs578-nlp/CS578Project/source$

Thanks a lot!

A: 

You are running the independent class without the right class path. If you add the jar reference to the manifest in a JAR file you do not need to add it to the class path when running it.

monksy
Unfortunately, I am new to Java and jar. Can you explain how I can do it?Thanks.
sefa kilic
And also what is wrong with my makefile?
sefa kilic
Its not, its how you are running the class.
monksy
java -cp <jarfile> Main
monksy
Anyway, I didn't understand the solution that you offer. But when I run my Main class with "java -classpath $CLASSPATH:jars/Jama-1.0.2.jar Main", it worked! Thanks for help.
sefa kilic
java -cp is the same as java -classpath
monksy