简体   繁体   中英

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.

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 java -classpath Jama-1.0.3.jar:. File_2 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM