0

I have used the more student-oriented IDE DrJava before, and did not have trouble running programs dependent on .jar files in the terminal/command line.

Right now I am writing a simple program to find eigenvalues of matrices in IntelliJ, and although I have followed the steps listed in the stack overflow question "Importing jar file into IntelliJ Idea?" to add the .jar file I am using as a dependency, I am getting errors like this when I try to compile the program in terminal:

javac eigenvalues.java
eigenvalues.java:11: error: package Jama does not exist
import Jama.*;
^

and etc. (more errors of the form such-and-such does not exist).

My program has multiple classes and I only need the .jar file for one of them.

The program compiles fine within intelliJ, just not from terminal.

JMK
  • 1
  • 1

1 Answers1

1

You can make it work by two ways: 1. You can try by putting the required JAR in the ext folder: Below is the path to ext folder, then try to compile.

On Linux Systems -    /urs/lib/JDK/jre/lib/ext/

On Windows Systems- C:/Program Files/Java/jdk..0.1/jre/lib/ext/
  1. You can add the path of that required jar to the CLASSPATH system variable also.

  2. You can compile the program by dynamically providing the classpath with javac command as below:

    javac -classpath "<Path to the JAR>" YourProgram.java
    

    There is a very good link on the classpath.

Hope It may work.

pbajpai
  • 1,303
  • 1
  • 9
  • 24
  • Thanks. I couldn't find the folder path in option #1 (I'm on a Mac, couldn't find the folder "ext"). As to option #2, I don't know what a system variable is and, although it would be good to learn, I think it's beyond the scope of what I'm doing. So I tried option #3 and it did compile, but then it wouldn't run. I'm getting this error: Exception in thread "main" java.lang.NoClassDefFoundError: Jama/Matrix at eigenvalues.main(eigenvalues.java:39) etc. Neither "java -classpath Jama-1.0.3.jar eigenvalues" nor "java eigenvalues" worked. (The .jar file is in the same directory). – JMK Jun 13 '16 at 18:39
  • Please check below answers, these may help you. Thanks. 1--> http://stackoverflow.com/questions/18144660/what-is-path-of-jdk-on-mac 2--> http://stackoverflow.com/questions/15826202/where-is-java-installed-on-mac-os-x – pbajpai Jun 14 '16 at 03:45