Java files packaged as EXE executable files

Source: Internet
Author: User

The Java file is packaged as an EXE file, divided into two steps, first using Eclipse to package the Java file into a jar file, and then using EXE4J to package the jar file into an executable EXE file

One: package Java files into jar files with Eclipse

If the Java file does not reference the external package, it can be packaged into a jar file, if it references an external package file, it is best to package it into a runnable Jar file, so that the external package files can be packaged in, although the package is a bit large, but save the trouble of not running on other computers. (I've packaged myself up as a Runnable Jar File, it's very simple, this process is no longer described here )

The steps to package a jar file are many online, copy one here.

The first step is to package the Java project into an executable jar file, first look at my Java project structure, Main.java is the program entry class, there is the Main function, the Config directory is some configuration files, Lib is used by the third-party class library

Start packing, simulate (Java project)-right mouse button-export

Pop-up window, select "JAR file" and click "Next"

Uncheck the "config" and "Lib" directories, and the Project Profile ". Classpath" and ". Project" generated by Eclipse, click "Next"

All by default, click "Next"

In the pop-up window, select the MANIFEST.MF file that we created and click "Finish"

The contents of my MANIFEST.MF file are:

Manifest-version:2.0main-class:pubmed.viewclass-path:lib/commons-math3-3.2.jar Lib/commons-math-2.2.jar lib/ Activation-1.1.jar Lib/antlr-2.7.7.jar Lib/apache-mime4j-core-0.7.2.jar Lib/axiom-api-1.2.13.jar lib/ Axiom-dom-1.2.13.jar Lib/axiom-impl-1.2.13.jar Lib/axis2-adb-1.6.2.jar Lib/axis2-adb-codegen-1.6.2.jar lib/ Axis2-ant-plugin-1.6.2.jar Lib/axis2-clustering-1.6.2.jar Lib/axis2-codegen-1.6.2.jar Lib/axis2-corba-1.6.2.jar Lib/axis2-fastinfoset-1.6.2.jar Lib/axis2-java2wsdl-1.6.2.jar Lib/axis2-jaxbri-1.6.2.jar lib/ Axis2-jaxws-1.6.2.jar Lib/axis2-jibx-1.6.2.jar Lib/axis2-json-1.6.2.jar Lib/axis2-kernel-1.6.2.jar lib/ Axis2-metadata-1.6.2.jar Lib/axis2-mtompolicy-1.6.2.jar Lib/axis2-saaj-1.6.2.jar lib/ Axis2-soapmonitor-servlet-1.6.2.jar Lib/axis2-spring-1.6.2.jar Lib/axis2-transport-http-1.6.2.jar lib/ Axis2-transport-local-1.6.2.jar Lib/axis2-xmlbeans-1.6.2.jar Lib/bcel-5.1.jar Lib/commons-cli-1.2.jar lib/ Commons-codec-1.3.jar Lib/commons-fileupload-1.2.jar lib/commons-httpclient-3.1.Jar Lib/commons-io-1.4.jar Lib/commons-logging-1.1.1.jar Lib/geronimo-annotation_1.0_spec-1.1.jar lib/ Geronimo-jaxws_2.2_spec-1.0.jar Lib/geronimo-jta_1.1_spec-1.1.jar Lib/geronimo-saaj_1.3_spec-1.0.1.jar lib/ Geronimo-stax-api_1.0_spec-1.0.1.jar Lib/geronimo-ws-metadata_2.0_spec-1.1.2.jar Lib/httpcore-4.0.jar lib/ Jalopy-1.5rc3.jar Lib/jaxb-api-2.1.jar Lib/jaxb-impl-2.1.7.jar Lib/jaxb-xjc-2.1.7.jar Lib/jaxen-1.1.1.jar lib/ Jaxws-tools-2.1.3.jar Lib/jettison-1.0-rc2.jar Lib/jibx-bind-1.2.jar Lib/jibx-run-1.2.jar Lib/jsr311-api-1.0.jar Lib/juli-6.0.16.jar Lib/log4j-1.2.15.jar Lib/mail-1.4.jar Lib/mex-1.6.2-impl.jar Lib/neethi-3.0.2.jar lib/ Regexp-1.2.jar Lib/tribes-6.0.16.jar Lib/woden-api-1.0m9.jar Lib/woden-impl-commons-1.0m9.jar lib/ Woden-impl-dom-1.0m9.jar Lib/wsdl4j-1.6.2.jar Lib/wstx-asl-3.2.9.jar Lib/xalan-2.7.0.jar Lib/xml-resolver-1.2.jar Lib/xmlbeans-2.3.0.jar Lib/xmlschema-1.4.7.jar

MF File considerations:
(1) The first line cannot be empty, there can be no blank lines between rows and rows, the last character of each line cannot be a space
(2) The last line must be a blank line
(3) There must be a space between the name and value of each property (after the colon)
(4) Each line of the file cannot exceed 72 bytes (typically 70 ASCII letters plus carriage return newline character), and if 72 bytes are not sufficient, another line begins with a space: a line that begins with a space is treated as a continuation of the previous line.

The purpose of the executable jar file is achieved by specifying "Main-class". In fact, we finally package the project into Exe,class-path can not be specified, in the packaging EXE when also specify CLASSPATH.

The second step, package the project into EXE, here to make it clear that not all the files are packaged into an EXE, the resource files can not be wrapped in, look down ↓

First, create a folder in any directory, preferably named and the project name is the same, I created a "simulate" folder on the F drive, and then all the resource files and our generated executable jar files (my Simulate.jar) are copied into this folder, Config directory and Lib directory, if you are afraid to execute the program on the machine does not install JRE, then you need to copy the JRE directory on your own machine, I installed the JRE5, the last directory structure:

Then use EXE4J to package the jar as an EXE file

Open exe4j, skip the Welcome, and click the second item in the left navigation directly, as we have already packaged the Java project as an executable jar file in advance.

In the pop-up window, select "JAR in EXE mode" and click "Next"

In the new window, take a name for our app, then select the EXE build directory (my F:\Simulate) and click "Next"

For the exe we want to generate name, if you want to create a custom icon, then select your ico file, if you do not want to run more than one of your programs on a computer, you can check "Allow only a single ...", click "Next"

Click the green "+" to set the program to run the class Path

First select our own executable jar file (my Simulate.jar) and click OK

Our Simulate.jar is added to class path.

Then click on the main class selection button in general, and in the pop-up window, exe4j will automatically search for the class that contains the main method in all the jars under the current class path, and list it because I currently only select the jar for my project. And my project only Main.jar contains the main method, so at a glance, directly select it click "OK", the program entry class is set to complete

After the Main class setting is complete, add all the required third-party class libraries to class path, and then click "Next" as the "Simulate.jar".

Enter the Java minimum JRE version number, which is lower than this version of the JRE cannot run the program, then click on "Advanced Options"-"Search sequence", set up our JRE, said before, if the client does not install the JRE do? That's okay we bundle one in

Click on the Green "+" to select the bundled JRE location

Select "Directiony" in the pop-up dialog, then select the JRE folder, note: This JRE directory is we copy the JRE directory to the current EXE generated directory, and the program uses the relative directory, preferably written. \jre, do not write in the picture. Jre5, Click OK to complete the bundle operation of the JRE.

After the JRE is bundled, click "Next"

By default, click "Next"

By default, click "Next"

By default, click "Next"

EXE in Build

OK, finish, click "Exit" to

Let's see what we've achieved!

Finally, we need to copy the JRE to the same directory as EXE, so that it can be run on a computer without a JDK.



Java files packaged as EXE executable files

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.