Home >Java >javaTutorial >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:
java -cp MyJar.jar:lib/* com.somepackage.subpackage.Main
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!