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.