MANIFEST.MF of executable jar packages

Source: Internet
Author: User

When packaging executable jar packages, MANIFEST. MF is always a headache, and this kind of problem often occurs.
An example:
================================================================================
manifest-version:1.0
Main-class:test. Main
Class-path:././lib/commons-collections-3.2.jar./lib/commons-dbcp-1.2.2.jar
./lib/commons-lang-2.3.jar./lib/commons-logging-1.1.jar

================================================================================
Each part explains:
Manifest-version MF File version number
Main-class class containing the Main method
Class-path the classpath when executing this jar package

Here are the points to note:
1. Manifest-version, Main-class, and Class-path followed by an English colon, followed by a colonSpace, and then the version number, class, and classpath.
2. The items in the Class-path should be usedSpaceDelimited, not a comma or semicolon.
3. If there are many items in the Class-path, the line too long will be error when it is written in a row, then it is necessary to write class-path in multiple lines. Note: Starting on the second line, you mustTwo spacesAt the beginning, more than three I have not tried, but do not have a space beginning and a space beginning is not good, I have tried.
4. Class-path after the end of writing must have aBlank Line
5. Some configuration files inside the jar package want to be placed outside the jar package, such as file config.properties: If the file is loaded in a path, such as New file ("./config/config.properties"), Then place the config.properties in the Config directory under the same directory as the jar package, that is, the "./" path is equivalent to the directory where the jar package is located, and if the file is loaded in the same way as the file under Classpath, For example, to load classpath:config.properties in spring, add "./" in the classpath of the profile of the MF file, and then place the configuration file in the same directory as the jar package. Of course, you can also add "./config/" to the classpath of the MF file's configuration file, and then place the configuration files under the Config directory in the same directory as the jar package.

How to run the jar package: You can always run the command in DOS, or you can create an execution script to execute it, especially in win. If it is often done, it is recommended that you create an executable script.

MANIFEST.MF of executable 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.