Double-click the jar package to execute the program, and double-click the jar package

Source: Internet
Author: User

Double-click the jar package to execute the program, and double-click the jar package

Source File: MyMenuTest. java

Compilation result:

The volumes in C: \ Users \ zhangbz \ Desktop \ demo> javac MyMenuTest. javaC: \ Users \ zhangbz \ Desktop \ demo> dir drive C are not labeled. The serial number of the volume is E637-C45FC: \ Users \ zhangbz \ Desktop \ demo directory <DIR>. <DIR> .. 1,527 MyMenuTest $1. class2014/12/22 1,779 MyMenuTest $2. class2014/12/22 561 MyMenuTest $3. class2014/12/22 534 MyMenuTest $4. class2014/12/22 2,570 MyMenuTest. class2014/12/22 2,884 MyMenuTest. java 6 files, 9,855 bytes, 2 directories, 64,374,337,536 available bytes, C: \ Users \ zhangbz \ Desktop \ demo>

What should I do if n classes are generated after compilation?

Encapsulate a package.

Add the package name in the first line of the source file as follows:

package mymenu;

Run the following command to re-compile:

C:\Users\zhangbz\Desktop\demo>javac -d . MyMenuTest.java

After re-compilation, all the generated class files are saved in the mymenu folder in the current directory.

Then specify the class with the main function executed when double-clicking the jar package:

Add a file in the directory where the mymenu folder is located (the file name is random) to specify the Main-class:

Main-class: mymenu.MyMenuTest

Requirements: ":" must be followed by spaces; the end of a line must be followed by a carriage return, indicating that the end of a line of input is over.

Finally, run the following command to re-package:
jar -cvfm my.jar 1.txt mymenu

Now, you can double-click the jar package to execute the java program.

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.