Running the jar package with Java-jar

Source: Internet
Author: User
Tags tmp file

Running the jar package with Java-jarIn fact, it is not difficult, online search a lot, but not full, or speak a lot, some details are missing, in this, I would like to point out the detailsJava-jar

1. In fact, the command is relatively simple: enter the corresponding directory, the execution of Java-jar Xxx.jar can!

2. But why can't the jar from MAVEN package or eclipse export run? The reason is simple, does not specify which class executes the main method, how to specify? Configuration file, there is a Meta-inf folder under the project folder, there is a MANIFEST.MF file under the Meta-inf folder, as long as you change the file.

3. The default content of this file is:

manifest-version:1.0
created-by:1.4.2 (Sun Microsystems Inc.)

Change it to

manifest-version:1.0
created-by:1.4.2 (Sun Microsystems Inc.)
Main-class:xxx.xxx.xxx.xxx

Attention:

Main-class the next X part is the package name. Class Name

Main-class: There's a space behind, and there's a blank line underneath.

4. After the content is changed, how do you make it into a jar package?

I tried to pack it directly with WinRAR and then change the suffix name, no,

Here's how it works:

Suppose your jar package is named Myjar.jar:

(1) First extract the Myjar.jar to Myjar (in the same layer folder)

(2) Enter the Myjar folder, then enter the Meta-inf folder, change the Manifest.mf file,

Follow steps three.

(3) Save back to Myjar.jar the same level directory, then execute Jar UMF myjar/meta-inf/manifest. MF Myjar.jar

If there is no error, and the Xxx.tmp file is generated, the execution succeeds,

Open Myjar.jar and you can see that the MANIFEST.MF file has been changed to the appropriate file.

(4) Java-jar Myjar.jar can be executed in the current directory

Running the jar package with Java-jar

Related Article

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.