Classpath problem with jar package referencing other jar packages

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.