Tuesday, October 2, 2012

Add external jar files in classpath when running Java programs from command prompt or shell

If you simply want to compile or run Java applications from command line, you can just add the jars to the classpath:
javac -classpath c:\path1\ext1.jar;d:\path2\ext2.jar de\example\MyClass.java

When running a java application, you have to add the classes folder as well
java -classpath bin;c:\path1\ext1.jar;d:\path2\ext2.jar de.example.MyClass

When running from command prompt on windows, you can also replace "bin" with a "."

Note that under *nix OS not a semicolon(;), but a colon(:) is used to separate classpath parts.

Reference:
1. http://www.coderanch.com/t/423052/java/java/solved-add-external-jar-windows

No comments:

Post a Comment