Java command-line in Linux

In Linux, when you use an IDE like Eclipse or JCreator, there is almost no difference from Windows when connecting jar libraries.

For command line, there are two main options.

Say you have corejava.jar in your ~/jars directory, and your current directory is where you have the source files.

One option is to set the CLASSPATH variable:

setenv CLASSPATH .:$HOME/jars/corejava.jar (in tcsh)
export CLASSPATH=.:$HOME/jars/corejava.jar (in bash)
and then use javac/java like usual. This is useful when setting CLASSPATH in initialization files.

Another option is to use the -classpath (or -cp) switch of javac/java:

javac -cp .:$HOME/jars/corejava.jar *.java
java -cp .:$HOME/jars/corejava.jar Main
This is more appropriate when using, e.g., a makefile.

Note that ':' is used to separate the classpath elements. In Windows that would be ';'.