When I\'m in Eclipse my project compiles with no errors, however when I try to compile with javac
it says I\'m missing some packages...
I copied my comp
-classpath lib/
will cause javac
to look for a tree of class files in lib
. If you have JAR archives there, you have to use -classpath lib/*.jar
- and probably use whatever escaping mechanism your CLI has on the * to make sure it reaches javac
rather than being expanded by the CLI
See the javac command reference (windows).
Existing answer, as informative as it is, still left me wondering, having to go over the javac -classpath docs. Here's a revision of what you might want to know:
javac -cp "lib/" Example.java
will load all .class
files in lib/
.
javac -cp "lib/\*" Example.java
will load all .jar
files in lib/
, but not the .class
files.
javac -cp "lib/;lib/\*" Example.java
will load all .jar
and .class
files in lib/
.
Notes:
*
(wildcard) character as used in above examples is escaped (note the \
before *
). \
is for bash, if you're using something else it might be different. You want to escape it because the java sdk utilities, like javac
, their own way of interpreting the wildcard. As far as I can tell (correct me if I'm wrong), Windows command line doesn't expand *
so you don't need to escape it: -cp lib\*
should be fine.;
separates paths, as in javac -cp ".;a/;b/;c/" Example.java
– this would load .class
files in the following directories: current directory, a, b and c.;
).