Home > Java > javaTutorial > How Can I Execute a JAR File with External Dependencies?

How Can I Execute a JAR File with External Dependencies?

Linda Hamilton
Release: 2024-12-13 14:29:13
Original
549 people have browsed it

How Can I Execute a JAR File with External Dependencies?

Executing JAR Files with Custom Classpath

Due to limitations with the "-jar" option, specifying "-cp" will have no effect. As per the Java documentation, using "-jar" makes the JAR file the sole source of user classes, overriding other classpath settings.

Additionally, JAR files cannot encompass other JAR files. To include necessary dependencies, you can either:

  • Include the JAR files from the "lib" directory in the manifest using relative paths.
  • Specify all JAR files on the command line using "-cp":
java -cp MyJar.jar:lib/* com.somepackage.subpackage.Main
Copy after login

This command will execute the main class from the specified JAR while loading dependencies from the "lib" directory.

The above is the detailed content of How Can I Execute a JAR File with External Dependencies?. 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