tags:

views:

434

answers:

5

I need an answer for the question in the title.

Thanks.

+2  A: 
export CLASSPATH=/your/stuff/

or preserving system wide settings:

export CLASSPATH=$CLASSPATH:/your/addition/
vartec
+2  A: 

If you mean the Java classpath (from your tag), then this is only different from Windows in terms of path-separators (: instead of ;). For example

java -classpath /mydir/mylib.jar:/otherdir/otherlib.jar com.MyProgram -Xmx64m
oxbow_lakes
+1  A: 

I don't think you should have a system classpath environment variable on Linux or any other operating system.

Each and every project should have its own classpath settings. They're usually set by scripts or convention, so there's no need for a system environment variable.

Besides, what would you do if two projects had conflicting JARs required?

Will that environment classpath include every JAR needed by every project on your machine? That's not practical.

A classpath environment variable might have been the standard with Java 1.0, but I don't think it should be now.

duffymo
A classpath variable can be set per process i.e. for the current shell and its spawned child processes only. This is common use on unix in java start scripts.
ordnungswidrig
A: 

Create a small shell script which sets the classpath:

#!/bin/bash
export JAVA_HOME=...

cp=$(find lib -name "*.jar" -exec printf :{} ';')
if [[ -n "$CLASSPATH" ]]; then
    cp="$cp;CLASSPATH"
fi

"$JAVA_HOME/bin/java" -classpath "$cp" ...
Aaron Digulla
You can omit -classpath "$CLASSPATH" because the java process will use the contents of the environment variable CLASSPATH anymway.
ordnungswidrig
I extended my example to build the classpath; it now leaves the CLASSPATH alone so child processes can pick up the original version.
Aaron Digulla