How to make javac find JAR files? (Eclipse can see them)

前端 未结 2 1221
刺人心
刺人心 2020-12-31 02:41

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

2条回答
  •  失恋的感觉
    2020-12-31 03:30

    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:

    • The * (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.
    • Surround the classpath with quotes (like in examples) when using separators (;).

提交回复
热议问题