Home > Java > javaTutorial > How to Add JARs to the Classpath for Java Compilation?

How to Add JARs to the Classpath for Java Compilation?

Patricia Arquette
Release: 2024-12-09 15:58:14
Original
719 people have browsed it

How to Add JARs to the Classpath for Java Compilation?

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
Copy after login

To temporarily include these JARs in your classpath, use the following command:

java -cp jar1:jar2:jar3:dir1:. HelloWorld
Copy after login

In Windows, use semicolons to separate the JARs:

java -cp jar1;jar2;jar3;dir1;. HelloWorld
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template