Solve the Problem of java running in the specified version of JRE

Source: Internet
Author: User

The main idea is to write a large number of java versions, and I don't know the version of java installed by the customer. to simplify the release, you can directly send the document to the client.

First, you must understand how java.exe looks for the JRE Library:

When java.exe is executed on the console, the operating system looks for JRE as follows:
1) First, check whether there is any JRE in the current directory.
2) check whether there is a JRE in the parent directory.
3) Find JRE in the PATH
4) Registry hkey_local_machinesoftware1_oftjava Runtime Environment to check which JRE the CurrentVersion key value points

2. JRE class library search

The basic library that comes with JRE is mainly the JRElib t. jar file, including all the class libraries of the Java 2 platform Standard Edition. The version is the same as that of JRE.

In JRE, ClassLoader is responsible for finding and loading the class libraries referenced by the program. The base class library ClassLoader will go to rt. jar is automatically loaded. Other class libraries and ClassLoader are searched in the path specified by the Environment Variable CLASSPATH. The class libraries placed before CLASSPATH are first searched, we recommend that you set the PATH and CLASSPATH environment variables before starting the Java program. OS uses the PATH to find JRE and determine the rt of the base class library. jar location. The ClassLoader of JRE uses CLASSPATH to find other class libraries. However, sometimes this happens. If you want to replace the class library in the base class library, you can simply pass it to java.exe through -djava.endrosed.path)...htm, so ClassLoader will use java before the base class library. endrosed. the path parameter specifies the path class library. Therefore, Java version management is very simple and effective. It may be very primitive, but it is easy to use, so it is not easy to make mistakes.

3. Java Virtual Machine startup and loading class library

After the leleexecutes the java.exe xxxcommand, for example, the osfinds jre.osfinds the jredirectory, transmits the parameters of java.exe, loads the jvm. dll of the Server version or the jvm. dll of the Client Version, loads the jvm. dll, and gives control to jvm. dll.

Next, jvm. dll initialization, memory allocation, and other actions, then find the class in the CLASSPATH path, find the class, find the Main function in the class program entry point, and then execute the program from the Main function, during execution, use ClassLoader to dynamically load a series of referenced classes. When the native method is called, jvm. dll tells the OS to find a XX DLL file in the JREin directory and transfer it to the memory, so JNI is called.

Finally, we want to use the target directory structure (take the test directory as an example ):
Test saves the. class,. jar and other files generated by the project java file.
Copy test/jre/bin to the bin directory in jdk.
Copy test/jre/lib to the jre/lib directory in jdk.
After creating the preceding directory results, you can send test/jre/bin/java.exe to the desktop shortcut.
Then, modify the target (T) tag of the fast-forward mode to.../test/jre/bin/java.exe test,
Note that the starting position (S) is changed together! As follows. : D

Now, try javaw.exe. You don't need the damn console window. I hope the above article will help you.

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.