Monday, July 1, 2013

Java classpath under linux

You use the -classpath argument. You can use either a relative or absolute path. What that means is you can use a path relative to your current directory, OR you can use an absolute path that starts at the root /.
Example:
bash$ java -classpath path/to/jar/file MyMainClass
In this example the main function is located in MyMainClass and would be included somewhere in the jar file.
For compiling you need to use javac
Example:
bash$ javac -classpath path/to/jar/file MyMainClass.java
You can also specify the classpath via the environment variable, follow this example:
bash$ export CLASSPATH="path/to/jar/file:path/tojar/file2"
bash$ javac MyMainClass.java
THE FIRST LINE MAY APPEAR IN THE .bashrc TO AUTOMATE THINGS A BIT

For any normally complex java project you should look for the ant script named build.xml


source: http://stackoverflow.com/questions/11459664/how-to-add-multiple-jar-files-in-classpath-in-linux

No comments:

Post a Comment