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

How do I import jars into my java program?

$
0
0

I've downloaded two jars. I want to import some of their contained classes. How do I do this?

It's for my algorithms class. I've tried following the instructions on the following site to no avail.

http://algs4.cs.princeton.edu/code/

There's an installer for OSX (I'm running Mountain Lion) which allegedly adds the jars to your classpath. Unfortunately it also installs Dr. Java. I'd rather just use Sublime and Terminal. I assumed it would be easy enough just...

import java.stdlib;

in my Percolation.java file, but javac-ing that program yields a "package stdlib does not exist", as does

import stdlib;

I've added the location of stdlib.jar and algs4.jar to my Terminal CLASSPATH manually via:

export CLASSPATH=$CLASSPATH:/Users/Michael/path/to/jar/algs4.jar:/Users/Michael/path/to/jar/algs4.jarexport CLASSPATH=$CLASSPATH:/Users/Michael/path/to/jar/stdlib.jar:/Users/Michael/path/to/jar/stdlib.jar

I've also attempted

javac -cp $CLASSPATH:/Users/Michael/path/to/jar/algs4.jar:/Users/Michael/path/to/jar/stdlib.jar Percolation.java

But I still get a

javac Percolation.javaPercolation.java:1: cannot find symbolsymbol  : class stdliblocation: package javaimport java.stdlib;       ^Percolation.java:2: package java.algs4 does not existimport java.algs4.WeightedQuickUnionUF;             ^

What's going on here?

Also is there a way to permanently add those values to my CLASSPATH in OS X mountain lion. I have to perform that command with every new Terminal.


Viewing all articles
Browse latest Browse all 14

Trending Articles





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