Get java path cmd

How to set JAVA_HOME in Windows 11/10

In Unix terminology, an Environment variable is a string that holds information such as drive name, pathname, filename, etc. JAVA_HOME is an environment variable which addresses to the directory where Java Runtime Environment or Java Development Kit is installed in the system. To be precise, say if you have installed Java in the path C:\Program Files\Java\jdk1.8.0_121 on your computer, then your Java_Home is C:\Program Files\Java\jdk1.8.0_121. Basically, JAVA_Home is simply an exemplary used by Java-based programs like Apache Tomcat and other app server tools to find where Java is placed in the system.

Читайте также:  Java net inetaddress getlocalhost java

These third-party programs make use of the environment variables that point to the directory of JDK or JRE. In simple words, it makes easy for the programs to locate the directory executable like javac in the computer. If you are not using these third-party programs, then it may not be mandatory for users to set up JAVA_Home in your system. In this article, we will explain in detail how to set JAVA_HOME as the environment variable in Windows 10.

Setting JAVA_HOME in Windows 11/10

Set JAVA_HOME environment variable & update the system path

Download and install Java from the official site – java.com.

After installation, Go to Start menu and type Advanced system settings.

Click on View advanced system settings from the list to open System Properties.

Go to Advanced tab and click on Environment Variables button.

In the Environment Variable window, click on New button under the System variable.

In the Edit System Variable, give the Variable name as JAVA_HOME and Variable value as the path to your JDK directory.

Click on OK.

Now go back to the Environment Variable window and select Path under the System variable.

How to set JAVA_HOME in Windows 10

Click on Edit button to open Edit environment variable window.

Click on New button and type %JAVA_HOME%\bin.

Click OK to apply the changes.

Check JAVA_HOME configuration setup using CMD

To test your configuration, open Command prompt.

Type echo %JAVA_HOME% and hit Enter. This should print the directory of the JDK which the JAVA_HOME is pointing. Instead, if you see a space, it means you have failed in setting up environment variable.

Next Type javac -version which should print the version of Java compiler.

If not it will print a message that the javac is not recognized as an internal or external command. This means the path variable is not set correctly.

Источник

How to set java path in windows 10

JAVA_HOME is environment variable which contains installation directory of Java development kit(JDK) or Java Runtime environment(JRE). This environment variable is setup at operating system level.

Why do you need JAVA_HOME?

JAVA_HOME environment variable points to directory where java is installed on your system, so many java based applications such as TOMCAT use JAVA_HOME environment variable to locate java executables.

How to set JAVA_HOME in Windows 10?

  1. Locate JDK on your machine.
    • If you are using 64-bit java, then it will be in C:\Program Files\Java\
    • If you are using 32-bit java, then it will be in C:\Program Files (x86)\Java\
  2. Open windows search, type environment and click on Edit the system environment variables . Edit environment variable in java
  3. In System properties dialog, go to Advanced tab and click on button Enviroment Variables . Click on Edit environment variable
  4. In System variables, click NEW. button to add JAVA_HOME environment variable. Add new environment variable
  5. Provide variable name as JAVA_HOME and value as Java installation directory. Set Java home environment variable

Set java path in window 10

Now let’s see how to set java in path environment variable in windows 10.

  1. In System variable window, locate Path and click on Edit. . Click on edit
  2. Double click on the empty row and add %JAVA_HOME%\bin . Set java path in windows 10
    Here, % symbol is used to locate JAVA_HOME environemt variable and \bin provides location for java.exe and h= javac.exe
  3. Close the command prompt and launch again.
  4. Check java version as below: Check java version

That’s all about How to set java path in windows 10.

Источник

Найти местоположение Java в Windows

Найти местоположение Java в Windows

  1. Найдите местоположение Java с помощью команды where java
  2. Найдите местоположение Java с помощью команды set JAVA_HOME
  3. Найдите местоположение Java с помощью команды dir /b /s java.exe
  4. Найдите местоположение Java с помощью команды gcm -All java в Windows PowerShell

Сегодня мы увидим, как узнать, где находится Java в Windows. Для этого есть несколько способов и команд; мы проверим различные команды, которые возвращают окна местоположения Java.

Найдите местоположение Java с помощью команды where java

Наиболее часто используемая команда для получения текущего местоположения Java в Windows — это where java . Это команда Windows, которая работает так же, как команда whereis в операционной системе Linux. Команда where используется для отображения местоположения исполняемого файла. Обычно используется шаблон поиска.

Как показано ниже, когда мы запускаем команду where java в командной строке Windows, она возвращает местоположение java.exe .

C:\User\.jdks\openjdk-15.0.1\bin\java.exe 

Найдите местоположение Java с помощью команды set JAVA_HOME

Следующий способ узнать местоположение Java в Windows — использовать команду установить JAVA_HOME . В Windows путь к Java или JDK хранится в переменных среды. Местоположение хранится в переменной с именем PATH , списке каталогов, которые можно использовать для прямого доступа к определенным программам, таким как Java, без записи всего пути.

Мы можем установить путь к Java командой set JAVA_HOME , а затем указать путь. Но если значение уже установлено, он вернет путь, установленный к переменной JAVA_HOME . Это завершает нашу задачу, поскольку это каталог, в котором находится Java.

C:\Users\Rupam Saini>set JAVA_HOME 
JAVA_HOME=C:\Users\Rupam Saini\.jdks\openjdk-15.0.1 

Найдите местоположение Java с помощью команды dir /b /s java.exe

Команда dir показывает все папки и подпапки в текущем местоположении. Мы можем использовать эту команду для получения местоположения Java, поскольку на одном компьютере с Windows может быть более одного исполняемого файла Java, поскольку некоторые программы используют свою собственную среду Java.

Мы используем команду dir с тремя параметрами, первым из которых является /b , который отображает только путь к каталогу без каких-либо дополнительных деталей. Напротив, параметр /s перечисляет все вхождения указанного файла в текущем каталоге и подкаталогах и, наконец, имя выполнения java.exe .

C:\User\.jdks\openjdk-15.0.1\bin\java.exe C:\User\AppData\Local\JetBrains\IntelliJ IDEA Community Edition 2020.3\jbr\bin\java.exe 

Найдите местоположение Java с помощью команды gcm -All java в Windows PowerShell

Во всех примерах в этом руководстве мы используем традиционную командную строку, но для этого метода требуется Windows PowerShell, командная строка, но с расширенными возможностями. В PowerShell мы используем команду gcm , сокращенно от get-command . Он возвращает все команды в машине.

Мы используем gcm с двумя параметрами; первый — -All , который показывает все экземпляры команды на текущей машине, а второй параметр — это имя команды. В нашем случае имя команды java . В свою очередь, он выводит некоторые сведения о команде, такие как тип команды, имя исполняемого файла, выполняемого по команде, версия и источник исполняемого файла. Источник — это место, где находится Java.

CommandType Name Version Source ----------- ---- ------- ------ Application java.exe 15.0.1.0 C:\User\.jdks\openjdk-15. 

Rupam Saini is an android developer, who also works sometimes as a web developer., He likes to read books and write about various things.

Источник

How to Set Path and Classpath in Java

Java PATH and Java CLASSPATH are two confusing environment variables for Java beginners. Both are operating system level Environment Variables.

What are Environment Variables ?

Many operating systems use environment variables to pass configuration information to applications. Java environment variables are key/value pairs, where both the key and the value are strings. There are many subtle differences between the way environment variables are implemented on different Operating Systems. For example, Variables in Windows are NOT case-sensitive , while UNIX does not. The way environment variables are used also varies. Environment variables are typically named in uppercase, with words joined with underscore such as: JAVA_HOME .

Environment Variables examples

JAVA_HOME : C:\Program Files\Java\jdk1.8.0 JDK_HOME : %JAVA_HOME% JRE_HOME : %JAVA_HOME%\jre CLASSPATH : .;%JAVA_HOME%\lib;%JAVA_HOME%\jre\lib PATH : your-unique-entries;%JAVA_HOME%\bin

Many problems in the installation and running of Java applications are caused by incorrect setting of environment variables especially in confoguring PATH, CLASSPATH and JAVA_HOME.

How to set Java path in Windows

Java PATH is the environment variable where we specify the locations of binaries. When you run a program from the command line, the operating system uses the PATH environment variable to search for the program in your local file system. In Java, for run any program we use ‘java.exe’ and for compile java code use javac.exe . These all executable(.exe) files are available in bin folder so we set path up to bin folder. The Operating System will look in this PATH for executable. You can set the path environment variable temporary (command line) and Permanent.

Set path from Windows command line (CMD)

Open command prompt and type the following on command prompt.

Set Java path from cmd

Set Permanent Path of Java in Windows

In Windows inorder to set

  1. Step 1: Right Click on MyComputer and click on properties

set java path windows 10

  1. Step 2: Click on Advanced System Setting

set java path windows 7

  1. Step 3: Select Advanced Tab and Click on Environment Variables

set java path windows 8

  1. Step 4: Then you get Environment Variable window and Click on New.

set java path windows 8.1

Then you get a small window «New System Variable» and there you can set «Variable Name» and «Variable Value». Set Variable Name as «path» and Variable Value as «your jdk path».

set java path windows

Click «OK» button. Now you set your Java Path and next is setting up ClassPath.

How to Set Classpath for Java on Windows

Java CLASSPATH is the path for Java application where the classes you compiled will be available. It is a parameter in the Java Virtual Machine or the Java compiler that specifies the location of user-defined classes and packages. The parameter may be set either on the command-line, or through an environment variable. If CLASSPATH is not set, it is defaulted to the current directory. If you set the CLASSPATH , it is important to include the current working directory (.). Otherwise, the current directory will not be searched.

In Windows inorder to set ClassPath :

Repeat the above steps: Steps1 to Step4 .

Then you get a small window «New System Variable» and there you can set «Variable Name» and «Variable Value». Set Variable Name as «ClassPath» and Variable Value as «your class path» (ex: C:\Program Files\Java\jdk1.8.0\lib\* ).

How to set java ClassPath

Using wildcards in java classpath

Wild cards were introduced from Java 6 . Class path entries can contain the basename wildcard character *, which is considered equivalent to specifying a list of all the files in the directory with the extension .jar or .JAR. For ex. a classpath entry consisting simply of * expands to a list of all the jar files in the current directory.

Example

where %MAINCLASS% is the class containing your main method.

How to use a wildcard in the classpath to add multiple jars

where %MAINJAR% is the jar file to launch via its internal manifest.

If you need only specific jars, you will need to add them individually. The classpath string does not accept generic wildcards like Jar*, *.jar, hiber* etc.

Example

The following entry does not work:

Источник

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