Java tip: Set the main class in a list

Source: Internet
Author: User

Does your user encounter difficulties when running javaapplications? You can create a Windows bat file or a Unix sh file to help him invoke application. But if you have a GUI, then you have a much simpler way to solve the problem.

On many modern desktops,. jar files are set to run automatically. This makes the application of jar files common to users. They download this stuff, put it on their desktops, and then click on them when they want to use it.

This magic has become surprisingly easy. Each. jar file has a manifest that is saved with the following file name:

Meta-inf/manifest. Mf

The jar command provides a-M option to specify the file to be used for the manifest. The following code is an application of this method. Let's create a jarcreator:

Jarmfmeta-inf/jarcreator.mf

Com.generationjava.tools.JarCreator.class

A very basic list contains the version number and the manufacturer, which is usually the vendor of the JDK. For example, the list in MacOSX is like this:

manifest-version:1.0

created-by:1.3.0 (applecomputer,inc.)

But the real move starts with the extra third line:

manifest-version:1.0

Main-class:com.generationjava.util.jarcreator

created-by:1.3.0 (applecomputer,inc.)

The third line provides the name of a class in which the static main function is run. It is equivalent to running Java commands that do not give any parameters in this class.

Once the jar is clicked, the main function of the Com.generationjava.util.JarCreator class will be invoked and the application will be implemented.

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.