How to determine if Java Virtual Machine is installed on Windows?

Using the code, how to install the Java virtual machine (and its version) on Windows.

+4
source share
5 answers

Assuming you want to programmatically determine this from a batch file, you can use the reg.exe tool installed in windows\system32 .

The annoying thing about this tool is that there is no way to return the exit code to it, so you need to suppress its output by redirecting to nowhere. And also generates an ERROR message when the value does not exist.

 @echo off rem rem DetectJvmInstalled.cmd rem reg.exe query "HKLM\Software\JavaSoft\Java Runtime Environment" /v "CurrentVersion" > nul 2> nul if errorlevel 1 goto NotInstalled rem Retrieve installed version number. rem The reg.exe output parsing found at http://www.robvanderwoude.com/ntregistry.php set JvmVersion= for /F "tokens=3* delims= " %%A IN ('reg.exe query "HKLM\Software\JavaSoft\Java Runtime Environment" /v "CurrentVersion"') do set JvmVersion=%%A rem if "%JvmVersion%" == "" goto NotInstalled :Installed echo JVM Version = %JvmVersion% exit /b 0 :NotInstalled echo JVM Not installed. exit /b 1 

Notes:

  • There are two redirects to the nul device, one for standard output and one for standard error.
  • Detection is performed separately from the parsing of the value so as not to display the message ERROR... when the value does not exist.
  • After the delims= option, there is a space character (since space is a delimiter).
  • The batch file returns an error / exit code from zero if it is installed (installed), or 1 if it fails (not installed).

Hope this helps.

+6
source

I think you might be interested to name them:

 System.getProperty("os.name"); System.getProperty("java.version"); 
+5
source

Oracle deployJava.js can not only check a certain minimum version of Java on the user's computer, but also on Windows, direct them through the download and installation, if necessary.

Usually deployJava.js is used to provide launch buttons for applications launched using Java Web Start and applets , you can use the JWS form to link to a "bare" Jar file (without dependencies).

+4
source

It is not possible to determine if the JVM is installed from Java code. Java code cannot work without the presence of the JVM. Therefore, if you can run the compiled code, the JVM is installed.

+3
source

I really don't think JVM can be installed on Windows. It would be more important for me to check if you have a JRE inside the directory of your hard drive, and whether this JRE is accessible through the link in the bin folder in the PATH environment variable.

You can verify this by trying to run java -version from code and collecting the output.

If you get a message with the message 'java' is not recognized as an internal or external command, operable program or batch file. then your jre is not referenced.

+2
source

Source: https://habr.com/ru/post/899682/


All Articles