Java command line environment

How to set environment variables for Java using command line

Well, in this article I talked about the JVM, JRE and JDK, which are the cornerstones of the Java programming language. You develop Java applications by using tools like editors, IDEs and servers. These tools need to use the Java compiler ( javac ) and Java launcher ( java ) to compile and run Java applications, but these tools don’t know where the JRE or JDK is.

So, by setting up the environment variables, you tell your tools that:

“Hey, you can find the compiler and launcher here and there”.

The first thing you need to do after installing the JDK is creating an environment variable named JAVA_HOME and then update the PATH variable.

  • JAVA_HOME : stores location of the JDK’s installation directory. When you install development tools, they will first check for the JAVA_HOME variable. If found, they will stick with it. If not, they may ask you to manually specify the location where JRE/JDK is installed.
  • PATH : stores paths of directories where the operating system will look, to launch the requested programs quickly. For Java development, you should update this environment variable by adding an entry to the bin directory under JDK’s installation directory.
  • JAVA_HOME = C:\Program Files\Java\jdk1.8.0
  • PATH = PATH + C:\Program Files\Java\jdk1.8.0\bin

But that isn’t cool, because I’m about to show you how to do the same thing using command line prompt as shown below (Windows 7, 8 and 10):

setx JAVA_HOME "C:\Program Files\Java\jdk1.8.0" setx PATH "%PATH%;%JAVA_HOME%\bin";

The setx command permanently updates the environment variables. To add/update system environment variables, you must use the -m switch and open the command prompt using Administrator privilege: Click Start, type cmd . When the cmd.exe icon appears, right click and select Run as administrator.

Читайте также:  Index php action detailview

To add/update system environment variables:

setx -m JAVA_HOME "C:\Program Files\Java\jdk1.8.0" setx -m PATH "%PATH%;%JAVA_HOME%\bin";

I prefer setting the environment variables using this command-line alternative. It’s quick and easy instead of going through several dialogs like using the GUI.

To summary, here are some important points:

  • Always set JAVA_HOME when preparing development environment for Java.
  • JAVA_HOME points to the installation directory of JDK.
  • The PATH variable should contain an entry pointing to JAVA_HOME\bin .
  • Environment can be set either via the GUI or command line prompt.

About the Author:

Nam Ha Minh is certified Java programmer (SCJP and SCWCD). He started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on Facebook and watch his Java videos you YouTube.

Источник

How to set environment variables for Java using command line

Well, in this article I talked about the JVM, JRE and JDK, which are the cornerstones of the Java programming language. You develop Java applications by using tools like editors, IDEs and servers. These tools need to use the Java compiler ( javac ) and Java launcher ( java ) to compile and run Java applications, but these tools don’t know where the JRE or JDK is.

So, by setting up the environment variables, you tell your tools that:

“Hey, you can find the compiler and launcher here and there”.

The first thing you need to do after installing the JDK is creating an environment variable named JAVA_HOME and then update the PATH variable.

  • JAVA_HOME : stores location of the JDK’s installation directory. When you install development tools, they will first check for the JAVA_HOME variable. If found, they will stick with it. If not, they may ask you to manually specify the location where JRE/JDK is installed.
  • PATH : stores paths of directories where the operating system will look, to launch the requested programs quickly. For Java development, you should update this environment variable by adding an entry to the bin directory under JDK’s installation directory.
  • JAVA_HOME = C:\Program Files\Java\jdk1.8.0
  • PATH = PATH + C:\Program Files\Java\jdk1.8.0\bin
Читайте также:  METANIT.COM

But that isn’t cool, because I’m about to show you how to do the same thing using command line prompt as shown below (Windows 7, 8 and 10):

setx JAVA_HOME "C:\Program Files\Java\jdk1.8.0" setx PATH "%PATH%;%JAVA_HOME%\bin";

The setx command permanently updates the environment variables. To add/update system environment variables, you must use the -m switch and open the command prompt using Administrator privilege: Click Start, type cmd . When the cmd.exe icon appears, right click and select Run as administrator.

To add/update system environment variables:

setx -m JAVA_HOME "C:\Program Files\Java\jdk1.8.0" setx -m PATH "%PATH%;%JAVA_HOME%\bin";

I prefer setting the environment variables using this command-line alternative. It’s quick and easy instead of going through several dialogs like using the GUI.

To summary, here are some important points:

  • Always set JAVA_HOME when preparing development environment for Java.
  • JAVA_HOME points to the installation directory of JDK.
  • The PATH variable should contain an entry pointing to JAVA_HOME\bin .
  • Environment can be set either via the GUI or command line prompt.

About the Author:

Nam Ha Minh is certified Java programmer (SCJP and SCWCD). He started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on Facebook and watch his Java videos you YouTube.

Источник

Оцените статью