The jar package double clicks the method that executes the program

  • 2020-04-01 03:38:17
  • OfStack

This article illustrates how to double-click a jar package to execute a program. Share with you for your reference. The specific implementation method is as follows:

Source file: mymenutest.java

Compile results:

C:UserszhangbzDesktopdemo>javac MyMenuTest.java
C:UserszhangbzDesktopdemo>dir
drive C There is no label in the volume.
The serial number of the volume is E637-C45F C:UserszhangbzDesktopdemo The directory where the 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 A file 9,855 byte
2 A directory 64,374,337,536 Bytes available C:UserszhangbzDesktopdemo>

How to generate n classes after compiling?

Get a package and wrap it up.

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

package mymenu;

Recompile using the following command:

C:UserszhangbzDesktopdemo>javac -d . MyMenuTest.java

After the recompilation, the generated class files are saved in the mymenu folder in the current directory

Then specify the class with the main function to execute when you double-click on the jar:

Add a file (at will) in the directory where the mymenu folder is located to specify main-class:

Main-class: mymenu.MyMenuTest

Requirements: ":" must be followed by a space; 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:

jar -cvfm my.jar 1.txt mymenu

At this point, you can double-click the jar to execute the Java program.

I hope this article has been helpful to your Java programming.


Related articles: