Java package jar file to run on a machine that does not have a JDK or JRE installed

Source: Internet
Author: User

Objective:

Java is called "compile once, run everywhere", but there is a premise that you have to install the Java environment on the machine. This is fine for developers or some other computer-savvy person, but it can be a hassle for some people who don't understand computers, and they want things to work instead of installing additional software. We can achieve this by encapsulating the JRE with the exported jar files.

method is very simple, is to configure the third-party library path, and then use their own JRE in the Javaw-jar xxx.jar command to run the jar file. Details are as follows:

1. Export the project as a jar file, which can be done with eclipse. This example is Excelfilter1.jar

2, in the jar file sibling directory to create a new Lib folder, the use of the third-party library in the inside, this example used in the operation of Excel Jxl.jar

3. Open the jar file with a compression tool (such as 360 compression) and edit the Meta-inf/manifest. MF file, add the path to the third-party library before the Main-class line: Class-path:lib/jxl.jar, note that each jar path is signed and followed by a space, if there are multiple jars, separated by a space

4. Create a new JRE folder in the jar file sibling directory and copy the JRE file under it

5. Create a new bat file in a sibling directory, such as Start.bat, and edit, write the following: Start Jre/bin/javaw-jar Excelfilter1.jar, save

After that, double-click the Start.bat to run the

As can be seen from the above, the key is to use the JAVAW command in your own JRE to run the jar, so you can usually use eclipse directly to export the project as an executable jar, if the system has a Java environment, then double-click to run; The jar can be run through the Javaw.exe in its own JRE.

Java package jar file to run on a machine that does not have a JDK or JRE installed

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.