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