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技巧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$
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.
精彩评论