Quantcast
Channel: How do I import jars into my java program? - Stack Overflow
Viewing all articles
Browse latest Browse all 14

Answer by pb2q for How do I import jars into my java program?

$
0
0

If you're using Terminal to compile and launch your program, then in the Terminal window, begin by setting the CLASSPATH:

$ export CLASSPATH=$CLASSPATH:/Users/Michael/path/to/jar1.jar:/Users/Michael/path/to/jar2.jar

Then you can type echo $CLASSPATH and see that the jars are referenced.

Now, in the same Terminal window, use javac to compile your class. Setting the CLASSPATH as above only applies to the current Terminal window and any processes launched from it.

Alternately you can pass the CLASSPATH to javac:

$ javac -cp $CLASSPATH:/Users/Michael/path/to/jar1.jar:/Users/Michael/path/to/jar2.jar MyClass.java

To persist this CLASSPATH for future Terminal sessions, add the export line above to the file .profile in your home directory.


Viewing all articles
Browse latest Browse all 14

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>