How to Include Jars in Classpath on Commandline (javac or apt)
When encountering compile errors like those shown below, it may be necessary to include additional JAR files in your classpath.
HelloImpl.java:3: package javax.jws does not exist import javax.jws.WebService; ^ HelloImpl.java:5: cannot find symbol symbol: class WebService @WebService ^ 2 errors
To temporarily include these JARs in your classpath, use the following command:
java -cp jar1:jar2:jar3:dir1:. HelloWorld
In Windows, use semicolons to separate the JARs:
java -cp jar1;jar2;jar3;dir1;. HelloWorld
Ensure you add the current directory ('.') to the classpath, as it is the default classpath (unless a CLASSPATH environment variable is defined). This command will set the classpath to include the specified JARs and the current directory.
The above is the detailed content of How to Add JARs to the Classpath for Java Compilation?. For more information, please follow other related articles on the PHP Chinese website!