Reputation: 103
I have a folder full of *.jar
files that I want to be included during compilation no matter what directory I'm in. As I currently understand it, and this could be completely wrong, I would have to make this change in /etc/environment
. So my /etc/environment
currently looks like this:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:
/usr/local/games:/~/Java/algs4/bin"
JAVA_HOME="usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java"
CLASSPATH="~/Java/algs4/bin:."
where ~/Java/algs4/bin
is the directory where my .jar
s are. But when I try to compile a program that uses these libraries javac doesn't recognize the libraries. What am I fudging?
java version is 1.7.0_51
Thanks in advance.
Edit: Here's my code that I'm trying to get to work
public class FixedCapacityStackOfStrings{
private String[] a;
private int N;
public FixedCapacityStackOfStrings(int cap){
a = new String[cap];
}
public boolean isEmpty(){ return N == 0;}
public int size() { return N;}
public void push(String item)
{
a[N++] = item;
}
public String pop()
{
return a[--N];
}
//test client
public static void main(String[] args){
FixedCapacityStackOfStrings s;
s = new FixedCapacityStackOfStrings(100);
while(!StdIn.isEmpty()){
String item = StdIn.readString();
StdOut.println(item);
if (!item.equals("-"))
s.push(item);
else if(!s.isEmpty()) StdOut.print(s.pop() + " " );
}
StdOut.println("(" + s.size() + " left on stack)");
}
}
Where StdOut and StdIn are the included in one of the .jar
files in /bin
. When I compile I get the error cannot find symbol
for StdIn and StdOut
Upvotes: 0
Views: 1541
Reputation: 325
Refer to this documentation. http://docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html
Class path entries can contain the basename wildcard character *, which is considered equivalent to specifying a list of all the files in the directory with the extension .jar or .JAR. For example, the class path entry foo/* specifies all JAR files in the directory named foo. A classpath entry consisting simply of * expands to a list of all the jar files in the current directory.
Upvotes: 0
Reputation: 287
you should include all jar files in the classpath.
CLASSPATH=.
for j in ~/Java/algs4/bin/*.jar; do CLASSPATH=$CLASSPATH:$j done
export CLASSPATH
CLASSPATH environment is ':' separated entries, both jar/zip file and directory.
directory is used to search .class files, not jar file
Upvotes: 1