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
Patricia ArquetteOriginal
2024-12-09 15:58:14717browse

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

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!

Statement:
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