JAVA · Generate EXE file with JAR package (exe4j software)

Basic method of using exe4j software

demand:

  • Premise: We have written the source code to realize a certain function;
  • Now we need to use our written .java file to generate an .exe file for users to use;
  • The user does not need to install a programming environment;
  • If users want to use the functions you have implemented, just run the .exe file you generated.

Tools needed:

  • eclipse software
  • exe4j software

solution:

  • Overall goal: generate .exe file using code to achieve the function
  • The first step: use eclipse to generate jar package using .java file
  • Step 2: Use exe4j software to generate exe executable file using jar package

Work content:

(1) Prepare in advance

  • Create a folder to store your application related files

  • First put the jre environment needed to run the executable file in it

  • Then copy the external jar package lib required by the source code (the picture is convenient, you can delete it later)
    Insert picture description here

  • As shown above, I created a new folder and added two folders, namely [jre environment] and [lib (external dependent package folder)]

    (The rest are added by me according to the demand, you can also increase according to the demand)

  • Here to talk about why you need [jre environment]?

    name Include content
    JDK Development kit with JRE
    JRE Operating environment, which contains the JVM (required to run java)
    JVM JAVA virtual machine

    : The user may not be a developer, and there may not be a java running environment on his computer, so we need to copy a [jre running environment] to the folder at the same time. Only when jre exists, can we execute the .exe file generated

(B) The first step: generate jar package

  • Open eclipse, right click on the project you created, select [Export]
  • According to the figure, select to generate [JAR file], click [next]
    Insert picture description here
  • According to the picture, click [Next] directly after completion

Insert picture description here

  • Then select the main class from the package you imported, and then select [Finish] to complete the generation of the jar package
    Insert picture description here

  • Explanation

  • Here is an additional explanation. In order to achieve the goal of generating jar packages, I also found many methods on the Internet. Many of them mentioned that if the program uses external jar packages, you need to manually create a MANIFEST.MF file to configure some resource paths .

  • However, the benefits of exe4j are revealed here. We don't need to create and configure the MANIFEST.MF file cumbersomely, we just need to add the external jar package we need in the exe4j program, and it will be OK.

(3) Second step: use exe4j to generate .exe file

  • Choose whether to load the original configuration, if not need to ignore

Insert picture description here

  • Select the type, select "JAR in EXE" here
    Insert picture description here
  • After configuring the file name and file output path, click [Next]

Insert picture description here

  • Set according to the picture. Note that if you use 64-bit jvm, you need to select [Advanced Options] to set up one more step, otherwise it will report:

    The JVM found at JAVA_HOME is damaged.Please reinstall or define EXE4J_JAVA_HOME to point to an installed 32-bit JDK or JRE
    

Insert picture description here

  • Click [Advanced Options] and select [32-bit or 64-bit]

  • Then select this item [Generate 64-bit executable]
    Insert picture description here

  • Then add jar packages as shown in the figure ( including source code generated jar packages and external dependent jar packages )
    Insert picture description here

  • As can be seen from the figure, I added two jar packages, one is generated by the source code, and the other is an external dependency on the jxl.jar package

  • Select the main entrance of your program according to the icon, and then select [Next]
    Insert picture description here

  • Select the JRE version number supported by the program
    Insert picture description here

  • Configure the JRE folder, [select the JRE folder in the folder we created earlier]
    Insert picture description here

  • After the addition is successful, the default settings can be selected later, if you are interested, you can study in depth

  • Finally, you can choose to save your configuration to this interface, and use it next time, which is the option we encountered at the beginning.

Insert picture description here

  • At this point, the program is generated successfully

(4) End

  • Look at the folder we finally got

Insert picture description here

  • Because the .exe file already contains our [generated JAR package] and [external dependency JAR package], we can delete them all

  • Combined with personal needs, you can add some instruction files or other necessary files in the folder

  • After running the .exe file, you can see that the above two files have been deleted and the program can still run normally

    (The picture is a small program for automatic scheduling that I have written to improve work efficiency [lazy])
    Insert picture description here

  • At this point, the executable program we generated can be copied and used on the user's machine, which is convenient and fast

—————————————————————————————————————————————

  • Record my study
Published 10 original articles · Like1 · Visits 138

Guess you like

Origin blog.csdn.net/qq_39419113/article/details/105534406