command to run the jar package:
Java-jar Hello.jar
However, if the project references other jars, you can see that the referenced jar is added to your jar when you package it with the IDE tool, but the runtime prompts classnotfoundexception.
At this point, you need to modify the MANIFEST.MF in the auto-generated Hello.jar of the IDE tool to specify additional jars to be used by the runtime through Class-path in MANIFEST.MF, and the other jars can be either the current path or a subdirectory under the current path. But cannot be included in the current jar.
Multiple jar files are separated by a space.
Take the following MANIFEST.MF file as an example
manifest-version:1.0
Main-class:com.ibm.portalnews.entrance.main
Class-path:lib\commons-collections-3.2.jar Lib\commons-configuration-1.5.jar Lib\commons-lang-2.3.jar lib\ Commons-logging.jar Lib\dom4j-1.6.1.jar Lib\jaxen-1.1-beta-7.jar Lib\jdom.jar Lib\log4j-1.2.14.jar
Where manifest-version represents the version number, which is typically generated automatically by IDE tools such as Eclipse
Main-class is the main class of the jar file, the entry of the program
CLASS-PATH Specifies the required jar, multiple jars must be on one line, and multiple jars are separated by a space, if the referenced jar is in the subdirectory of the current directory, Windows uses \ to split, Linux down/split
Class-path must have a blank space after the colon, or an error will occur
The last line of the file must be a carriage return line break, or else an error will occur
The edited MANIFEST.MF can be saved and, when using Eclipse, choose the use existing manifest from workspace option to manually specify the MANIFEST.MF file instead of Eclipse auto-generation.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Classpath problem with jar package referencing other jar packages