The example in this article describes how to double-click the jar package to execute the program. Share it with everyone for your reference. The specific implementation method is as follows:
Source file: MyMenuTest.java
Compilation result:
Copy the code as follows: C:/Users/zhangbz/Desktop/demo>javac MyMenuTest.java
C:/Users/zhangbz/Desktop/demo>dir
The volume in drive C has no label.
The serial number of the volume is E637-C45F
Directory of C:/Users/zhangbz/Desktop/demo
2014/12/22 19:57 <DIR> .
2014/12/22 19:57 <DIR> ..
2014/12/22 19:57 1,527 MyMenuTest$1.class
2014/12/22 19:57 1,779 MyMenuTest$2.class
2014/12/22 19:57 561 MyMenuTest$3.class
2014/12/22 19:57 534 MyMenuTest$4.class
2014/12/22 19:57 2,570 MyMenuTest.class
2014/12/22 15:17 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 multiple categories are generated after compilation?
Make a package and encapsulate it.
Add the package name in the first line of the source file, as follows:
Copy the code as follows: package mymenu;
Recompile using the following command:
Copy the code as follows: C:/Users/zhangbz/Desktop/demo>javac -d . MyMenuTest.java
After recompiling, the generated class files are saved in the mymenu folder in the current directory.
Then specify the class with the main function that is executed when the jar package is double-clicked:
Add a file (the file name is arbitrary) in the directory where the mymenu folder is located to specify Main-class:
Copy the code as follows: Main-class: mymenu.MyMenuTest
Requirements: There must be a space after ":"; there must be a carriage return at the end of the line to indicate the end of a line of input.
Finally, execute the following command to repackage:
Copy the code as follows: jar -cvfm my.jar 1.txt mymenu
This is complete, you can double-click the jar package to execute the java program.
I hope this article will be helpful to everyone’s Java programming.