I had a problem with compiling and running a java file in command line where it imports an external jar files. Here is the solution I've found.
Compilation
javac -cp <path to where the source codes resides>;<path to where the jar file resides> Example.java
run
java <path to where the source codes resides>;<path to where the jar file resides> Example <command-line arguments if any>
Note 1: separator ; for windows and : for unix
Note 2: multiple jar files can be used delimited by ;
Note 3: . can be used to specify the current directory
Sunday, December 12, 2010
Dealing with external jar files on command prompt
Subscribe to:
Post Comments
(
Atom
)
Thanks for sharing information dude. keep it up.
ReplyDeleteJavin
Why String is immutable in Java
Thanks a lot for the encouragement :-)
ReplyDelete-pavithra
Thanks. Since Java 6 there is also a path wildcard available.
ReplyDeleteFor example:
java -cp "lib\*;lib\sub\*" Example
This command adds all *.jar and *.JAR files from lib and lib\sub directory to the classpath.
http://download.oracle.com/javase/6/docs/technotes/tools/windows/javac.html