How to enable your java program to run on any machine by double-clicking

Source: Internet
Author: User

How to enable your java program to run on any machine by clicking
You can execute java.exe on any directory on the machine where jreis installed. Because it is copied to the system32 directory of windows during installation, and the latter will be in the path environment variable anyway. This java.exe

In the end, the Registry will be accessed to determine the location of the real JRE. If we have not installed JRE but only installed jdk, we need to set the environment variable. After the environment variable is set, we can execute it in any directory.
Javac.exeor java.exe. If we want every application to have its own JRE, neither of these two methods will work. However, java.exe searches for JRE in its parent directory.

Suppose that the package of our application is called JavaApplication. jar, which is stored in the JavaCode directory. In the JavaCode directory, we can execute java-jar JavaApplication. jar to run our program.

The JRE we installed is under d: Javajre1.5.0. Now, we only need to copy the jre1.5.0 directory to the JavaCode directory and change it to a name that is easy to write, such as jre. The JavaCode directory contains the following content:
JavaCode:
JavaApplication. jar
Jre:
All contents in the Jre1.5.0 directory (excluding the Jre1.5.0 directory, including the bin directory and lib directory)

Java.exe is in the bin directory under the jre directory. Java.exe searches for jre in its parent directory. The experiment shows that it searches for the lib directory, while lib is in the jre directory. For this reason, java.exe will determine the jre's location and then be normal.

Executing the java program will not worry about whether we have installed JRE, and whether there are registration items in the registry.

Check whether JRE under the JavaCode directory is used
Run cmd To Go To The JavaCode directory (assuming it is on the edisk) under the command line and point the path to the JRE under JavaCode:

Set path = e: JavaCodejrein

Java-verbose-jar JavaApplication. jar



The size of JRE 1.5 with 70 MB as private JRE is obviously too large, but many of them can be avoided. The licenseunder the jredirectory can be unwanted. Only java.exe1_javaw.exe is reserved for the execution file under the BIND directory.

Retain the rt, jsse, jce, and charsets databases. Except for the i386 and zi sub-directories, do not use any other sub-directories. Under Zi, you only need to keep the subdirectories of your region and some files under it. Besides

Attribute files outside the database must be retained. Run our applications several times each time you clean up and tune unwanted content to ensure that our JRE is not missing anything.

If we hope that an. EXE file like vcss can directly start our application, the simplest way is to write a P processing tutorial.
In A. txt file, such as autotun.txt, write as follows:
Set path = .. jrein
Java-jar JavaApplication. jar

In this way, the loaded DOS window appears until you close the Java program. If you want to avoid this DOS window when running your program, you can write as follows:

Start javaw-jar JavaApplication. jar

The DOS window will flash, because javaw is a command that requires dos loading.

Then, the suffix of the txt file is changed to bat or cmd. Finally, put the script Autotun. bat or Autotun. cmd in the JavaCode directory.

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.