What are Java-related operating system variables for? [closed]

closed . This question needs to be more objective and is not currently accepting answers.

want to improve this question? update the question to focus on just one problem when edit it .

Closed 1 year ago .

improve this question

There are environment variables that Java uses to perform certain actions, such as JAVA_HOME, CLASSPATH, Path,... Most of the material talking about these variables is confusing, many sometimes some information is left out or one source denies the other, so it is difficult to know what the real purpose of the variables is.

So I wanted to know what these variables are for and what value should I assign to them?

Author: NinjaTroll, 2019-10-05

1 answers

I will give examples in Windows, but all that changes are the paths of the folders.

Environment variables in general are used as a way to configure some application in a simpler way. Java searches for this information in the operating system to get some specific data, such as an executable file.

Java can use the following environment variables: JAVA_HOME, CLASSPATH, Path, JDK_HOME and JRE_HOME, JAVA_TOOL_OPTIONS, JDK_JAVA_OPTIONS, _JAVA_OPTIONS and JAVA_OPTS.

Note that it is not necessary to have all these variables set to run Java, most of the time only JAVA_HOME, CLASSPATH and Path are used.

  • JAVA_HOME:

    • points to the Java base folder (more precisely the JDK folder if you have installed it, something like this: "C:\Program Files \ Java \ jdk12.0. 5_24", if you did not change the Java folder from place when installing. The same goes for JRE).
    • this variable is used to flexibly change the value of the other variables when we update the Java version, just change the value of this variable. It can also be used by other programs to locate the Java folder.
  • CLASSPATH:

    • points to third-party libraries, such as JavaFX itself, which already comes inside Java files but is not included in it.
    • the value of this variable has to be some things that are not even in Java as".; % JAVA_HOME% \ lib; % JAVA_HOME% \ jre \ lib;". Note that"."it is the current folder we are in (when compiling a file in Java), the"; ' s "separate the paths and finally" % JAVA_HOME% " is taking the value of the variable JAVA_HOME and putting there.
    • using an example with JavaFX the value of this variable would have what I cited above and: "...; % JAVA_HOME% \ jre \ lib\jfxswt.jar;'. The file I specified contains all JavaFX packages compressed in one file .jar.
  • Path:

    • this is a widely used variable by the system.
    • it points to a folder that contains files that execute certain commands written on the command line, such as javac, java, jshell, jjs, jvisualvm , among others.
    • the value of this variable must be:"...; % JAVA_HOME% \ bin". Note that this variable may have other values already predefined in.
  • JDK_HOME and JRE_HOME:

    • these folders simply point to the JDK or JRE folder.
    • If you downloaded the JDK, in the jre_home variable put the value: "% JAVA_HOME% \ jre". Otherwise, just put " % JAVA_HOME%". Do not set JDK_HOME if you installed JRE.
    • in JDK_HOME just put as value " % JAVA_HOME%".
  • JAVA_TOOL_OPTIONS and JDK_JAVA_OPTIONS (Java 9+):

    • these variables they configure certain things in java when it comes to interpreting and compiling some file .java, but there is a certain difference.
    • JDK_JAVA_OPTIONS is used only by the java command.
    • JAVA_TOOL_OPTIONS is also used by other commands such as jar and javac.
    • as there are several, I recommend that you search the documentation for the values of these variables.
  • _JAVA_OPTIONS and JAVA_OPTS:

    • JAVA_OPTS should be ignored and no value, it is not used by the JVM.
    • _JAVA_OPTIONS is not documented, it does the same thing as JAVA_TOOL_OPTIONS. This variable is above the command line arguments, and JAVA_TOOL_OPTIONS is above this variable.
 2
Author: NinjaTroll, 2019-10-05 21:27:08