Home >Java >javaTutorial >How Do I Include JARs in the Classpath for Command-Line Java Compilation?
Including Jars in Classpath for Command-Line Compilation
To resolve compilation errors encountered when attempting to run a web service program, it's necessary to include relevant jars in the classpath. This can be done directly from the command line using the -cp option.
Example:
java -cp jar1:jar2:. HelloWorld
This command includes the jars named jar1 and jar2 in the classpath, as well as the current directory (.). The current directory is necessary as it's the default location for source files.
Note:
By specifying the jars in the classpath via the command line, you can temporarily include them without permanently modifying your bash_rc file or creating a manifest text file. This is a straightforward solution for including required jars on a case-by-case basis.
The above is the detailed content of How Do I Include JARs in the Classpath for Command-Line Java Compilation?. For more information, please follow other related articles on the PHP Chinese website!