moki
moki

Reputation: 3

Execute a java class file that uses class from a jar file

I have a java source file named File_2.java that starts with import Jama.*; and it contains the main method.
The current directory contains java source file File_2.java and the Jama-1.0.3.jar file

I can compile the source File_2.java using

javac -classpath Jama-1.0.3.jar File_2.java

This generates a File_2.class file in the current directory which is not getting executed. I have tried the following

$ java File_2
Exception in thread "main" java.lang.NoClassDefFoundError: Jama/Matrix
at File_2.main(File_2.java:32)

and

$ java -classpath Jama-1.0.3.jar File_2
Error: Could not find or load main class File_2

Thus my question is how do I execute the File_2.class file ? Kindly help.

Upvotes: 0

Views: 139

Answers (1)

delca85
delca85

Reputation: 1276

You have to add your current directory to in order to find your class file.
You must run java -classpath Jama-1.0.3.jar:. File_2.

Upvotes: 2

Related Questions