Correctly set the jre environment and jdk of java of idea

After installing jdk, I opened up the path, and javac is ok at any place, but an error will be reported when java is executed, which is puzzling. Later, after discovering the difference between jdk and jre, the problem was solved:

First of all, jdk is a development tool that needs to configure system environment variables and path, but jre is only a running environment. For example, a downloaded and installed java program needs this environment to run, so it is automatically installed, so path and system environment variables are automatically configured. The jdk decompression package contains the jre directory, which contains the jre operating environment and client of the same version, and the dll virtual machine file that runs under win.

Therefore, in the environment variable setting, a key value named: JRE_HOME is added. After saving in D:\JDK1.8\jdk1.8.0_31\jre, java can be executed under any path, and the solution is ok.

Appendix: (Transfer) Regarding jdk and jre, 

everyone will definitely choose whether to install a separate jre when installing the JDK. Generally, they will install it together. I also recommend that you do this. Because this can help you figure out the difference: 

Jre is a java runtime environment, it is the running environment of java programs. Since it is running, of course, it must include jvm, which is the familiar virtual machine, and all the class files of the java class library are packaged into jars in the lib directory. You can verify by yourself. As for which file is the virtual machine on windows? Anyone who has studied MFC knows what a dll file is, so let’s see if there is a jvm.dll in jre/bin/client? That is the virtual machine. 

Jdk is a java development kit, a java development kit, which contains various class libraries and tools. Of course it also includes another Jre. So why include another Jre? And jdk/jre/bin contains a jvm.dll in both the client and server folders. Explain that there are two virtual machines. I wonder if you have noticed this? 

I believe everyone knows that there are various commands used by java programs in the bin of jdk. The most obvious difference from the bin directory of jre is that javac is available under jdk. This is easy to understand, because jre is just a running environment. It has nothing to do with development. Because of this, a jdk with development functions will have both client-type jvm and server-type jvm under its own jre, and only the client-type jvm.dll is enough for jre as the operating environment. . 

Remember to set the jdk/bin path in the environment variable path? This should be the first step for everyone to learn Java. The teacher will tell you that javac and java cannot be used if you don't set it. Indeed the jdk/bin directory contains all the commands. But has anyone thought that the java command we use is not in the jdk/bin directory but in the jre/bin directory? If you don’t believe me, you can do an experiment. You can cut the java.exe in the jdk/bin directory to another place and run the java program. What do you find? Everything is OK! 

So someone will ask? I obviously did not set the jre/bin directory to the environment variable? 

Imagine that if java is for most people to use, they don’t need jdk for development, only jre is needed to make the java program run, so how much trouble does each customer need to manually set environment variables? So when installing jre, the installer will automatically add jre's java.exe to the system variables. The verification method is very simple. You can see that the path of the system environment variable has "%SystemRoot%system32;%SystemRoot%;" at the top of the path. Such a configuration, then go to Windows/system32 to have a look, what did you find? There is a java.exe. 

If you can force jdk/bin to move to the front of the system32 variable, of course you can also force the use of java in jdk/jre, but unless necessary, I don’t recommend this. Using a separate jre to run a java program can also be regarded as a kind of test in a customer environment. 

————————————————————————————————————————— In 


layman's terms: jdk is The java development kit includes jre; jre is just the runtime environment of java; and the JDK includes the same version of the JRE, in addition to the compiler and other tools. 

    JDK is the abbreviation of the Java Development Kit (java Development Kit). It is a development environment that builds applications, apples and components released on the java platform. JDK is the foundation of all java applications, and all java applications are built on top of this. It is a set of APIs, or some Java Class. To become a Java programmer, JDK is the most essential tool. 

    JRE is the abbreviation of Java Runtime Environment. It is basically the same concept as the Java virtual machine. Generally speaking, when talking about a specific product, you can say "JRE", and when talking about a model in theory, we often use "Java Virtual Machine". To use Java programs, JRE is an indispensable environment. 

If multiple versions of jdk are installed in the machine, as follows: 

BEA Weblogic Server 7.0 comes with a set of JDK1.3.1_02 
downloaded a set of the latest JDK1.4.1_02 
JBuilder9 comes with a set of JKD1.4.1_02 
Oracle8.1.7 comes with one Set of JRE 1.1.7 
Ration Rose comes with a set of JDK1.3 
DreamWeaver comes with a set of JDK1.3 

      6 sets of JRE, each set of JRE is installed in a different directory, will not affect each other. When java.exe is executed on the console, the operating system looks for JRE in the following way: 

First find whether there is JRE in the current directory,
then find whether there is JRE in the  parent directory, 
then find JRE in the PATH path (generally search from the path during runtime, according to the order of path setting, whichever is above) 
Registry HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft \Java Runtime Environment\ See which JRE the key value of CurrentVersion points to (usually this under XP: C:\Program Files\Java\jre6) The 

      most commonly used is to find JRE in the PATH path. Generally, before running your own program They will first temporarily set the PATH in the batch file, and put the JRE they use at the top of the PATH, so they will definitely run the JRE they bring without causing version confusion. 

———————————————————————————————————————————— 
JDK is Java Development Kit. Simply put, JDK is an SDK for developers. It provides a Java development environment and operating environment. SDK is Software Development Kit generally refers to software development kits, which can include function libraries, compilers, etc. 
JRE is Java Runtime Enviroment, which refers to the operating environment of Java, and is for users of Java programs, not developers. 
If JDK is installed, your computer will have two sets of JRE, one is located in \jre and the other is located in C:\Program Files\Java\jre1.5.0_15 directory, the latter one is less Server than the previous one End Java virtual machine, but just copy the previous set of Server-side Java virtual machine. And when installing the JDK, you can choose whether to install the JRE located in the C:\Program Files\Java directory. If you only install JRE instead of JDK, only one set of JRE will be installed in the C:\Program Files\Java directory. 
The status of JRE is like a PC. The Win32 applications we write need the operating system to help us run. Similarly, the Java programs we write must also need JRE to run. So after you install the JDK, if you install two sets of JRE in two different places on the hard disk, then you can imagine that your computer has two virtual Java PCs, both of which have the function of running Java programs. So we can say that as long as your computer has JRE installed, you can run Java applications correctly. 
1. Why does Sun ask the JDK to install two sets of the same JRE? 
This is because there are many development tools written in Java (such as javac.exe, jar.exe, etc.) in the JDK, and they are all placed in \lib\tools.jar. As can be seen from the following example, first rename tools.jar to tools1.jar, and then run javac.exe, the following result is displayed: Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac /Main this It means that you type javac.exe and type java -cp c:\jdk\lib\tools.jar com.sun.tools.javac.Main are the same, and you will get the same result. From here we can prove that javac.exe is just a wrapper, and the purpose of production is to prevent developers from typing too long instructions. And it can be found that the programs in the \lib directory are very small, no more than 29K. From this we can draw a conclusion. That is, the tools in the JDK are almost written in Java, so they are also Java applications. Therefore, if you want to use the tools attached to the JDK to develop Java programs, you must also attach a set of JRE yourself, so it is located in C:\Program Files\ The JRE in the Java directory is used to run general Java programs. 
2. If two or more JREs are installed on a computer, who decides? 
This major task falls on java.exe. The job of Java.exe is to find a suitable JRE to run Java programs. Java.exe searches for JRE in the following order: whether there is JRE in its own directory; whether there is JRE in the parent directory; query the registry: [HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment] So the running result of java.exe is consistent with yours Which JRE is executed in the computer has a lot to do. 

ADD: (Summary) 
1. JVM - java virtual machine JVM is what we often call the java virtual machine. It is the core part of the entire java implementation of cross-platform. All java programs will first be compiled into .class class files, which can be found in Execute on the virtual machine, that is to say, the class does not directly correspond to the machine's operating system, but indirectly interacts with the operating system through the virtual machine, and the virtual machine interprets the program to the local system for execution. 2. JRE - java runtime environment JRE refers to the java runtime environment. The JVM alone cannot be the execution of the class, because when interpreting the class, the JVM needs to call the class library lib required for the interpretation. In the JDK installation directory, you can find the jre directory. There are two folders bin and lib. Here you can think that the bin is the jvm, and the lib is the class library required for jvm work, and the jvm and lib are combined It's called jre. So, after you write the java program and compile it into a .class, you can package the .class file with jre and send it to your friends, so that your friends can run the program you wrote. (There is java.exe running .class in jre) 3.JDK - java development kitJDK is a java development kit. Basically everyone who learns java will install a JDK on the machine first, so what parts does it contain? ? Let's take a look at the installation directory of the JDK. There are six folders under the directory, a src class library source code compression package, and several other declaration files. Among them, the following four folders are really effective when running java: bin, include, lib, jre. Now we can see such a relationship, JDK contains JRE, and JRE contains JVM. bin: The most important thing is the compiler (javac.exe) include: header files used for interaction between java and JVM lib: class library jre: java operating environment (note: the bin and lib folders here and the bin and lib in jre are Different) Generally speaking, JDK is used for the development of java programs, while jre can only run classes without compiling functions. 
Other IDEs such as eclipse and idea have their own compilers instead of the ones that come with the JDK bin directory, so you will find that they only require you to select the jre path during installation. 

Guess you like

Origin blog.csdn.net/ccpit2b2c/article/details/104077574