How to check is Java is installed on Windows? - java

How to check, is Java is installed on Windows systems ?

You can read this out of the registry. Look in this key:
HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Runtime Environment
and read the string value named:
CurrentVersion
This setting lives in the 32 bit view of the registry, so if you ever build 64 bit code make sure you include the KEY_WOW64_32KEY flag.

Visit the officail website http://www.java.com/en/download/testjava.jsp and click "test currently installed version of java"

Some information which might be helpful:
a Java run time environment (JRE) can be installed by simply copying it to the computer (no Windows system entries are required)
there can be many different JRE versions on the computer at the same time (many commercial apps are bundled with their own JRE)
your Delphi app could check whether there is a java.exe in the system path (and so avoid scanning all folders)
the JAVA_HOME environment variable normally indicates the location of the Java Development Kit (JDK), but in a typical installation the JDK directory also contains a JRE folder

For my Inno Setup I check this key :
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Applications\javaw.exe
If I remove JAVA the key doesn't exist anymore.

Related

How Does Java Set It's Path and How Do I Change It?

So I installed the Java 14 JDK (Oracle) and then the Java 8 JRE (Oracle) and before I installed the Java 8 JRE I set the JAVA_HOME system variable to "C:\Program Files\Java\jdk-14.0.1 and added %JAVA_HOME%\bin to PATH and it worked perfectly, the Java 14 JDK was being used for the command prompt and after I installed the Java 8 JRE now Java 8 is being used for command prompt and when I went to check all the information literally nothing was changed so why isn't Java 14 being used for command prompt and how do I fix it?
How does this work?
There is a java.exe in C:\Windows\System32 or something similar that is commonly on the path that points at your 'current' installation, which is controlled by a registry key (HKLM/Software/JavaSoft/ or something similar). Installing the JRE8 second overwrote the 'current version' choice in that registry key, which is causing the java.exe in the system path to go for that one, and not the java.exe from JDK14.
Do you need a JRE / JREs are obsolete.
The real problem is installing a JRE8. Why did you do that? You probably do not need it. You don't need a JRE to run java stuff if you have a JDK (a JDK has all things that a JRE has), JREs as a concept is dead (starting with java9, there are no JREs anymore; the model has changed; instead of end users downloading JREs from oracle and your app from you, the new model is that end users download the JRE and the app, all from you, using for example jlink to create a custom (smaller) JRE just for your app, and thus end users no longer have this 2-step thing which is confusing, and you get to control which version of the 'JRE' is installed, as you installed it).
How do I fix it?
There might be a control panel widget to change the way the win\sys32 java.exe works. Otherwise, go hunt for that JavaSoft key in the registry, find the subkey in there called 'Current Version', and change it to the same key as what describes the j14 install (probably that key is called '14').
That, or, just uninstall JRE8. You don't need it, it's basically unsupported software at this point; leaving it installed is not great for your system's security.

Different JRE installations (windows)

When I download and install Java 8 (JRE) from: http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html
I can see the folowing registry key:
[HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment]
"CurrentVersion"="1.8"
However if I download and install Java 8 (JRE) from:
https://www.java.com/en/download/
I got the following registry key:
[HKEY_CURRENT_USER\Software\JavaSoft\DeploymentProperties]
I need to detect if Java 8 (JRE) is installed, should I check them both? Are there other registry location I need to check?
What’s are the differences between the two installers? Are they both providing the same Java JRE or there are any differences?
Thanks
Maybe I would try different approach, try look for java(w).exe on system variable PATH. It should point to latest installation of JRE - assuming latest directory entry in PATH.
Also if your application require specific JVM then its also possible to include JRE with your application. Just pack it inside and make sure your JRE is started. Many companies doing it for very good reason.
You should consider 32bit installations on a 64 bit machine as well.
In Microsoft's techNet site I found a vbs script to be used to determine the java version. Hope it helps. TechNet article on determining the version of java on windows

Check jdk/JRE is installed and get path for jvm.dll

Prgrammatically, how to check if java is insalled and get path from jvm.dll ?
Java can be installed anywhere, and there is no guarantee that you should be able to see, where. So, the general answer to your question, is "it is impossible", or that "you had to run a recursive file search for jvm.dll on your whole filesystem".
But this is not, what you want. I think, you want to get a "default" java or jvm, which will be used by java tools or any java software.
Normally you can find that in the $JAVA_HOME environment variable (on windows, %JAVA_HOME%) the actual jdk or jre install, which should contain jvm.dll.
If it doesn't work, it is a configuration problem on the system, but maybe it can happen. Your second choice should be to find a java.exe or a javaw.exe somewhere in your system path ($PATH or %PATH% on windows).
There are a lot of tools, or java softwares which are coming out with their own java/jvm instance, especially oracle like to give out them. In their case, only the general solution works.
You can also Write a Java program that prints out the value of the java.home system variable. For example:
System.out.println(System.getProperty("java.home"));
then invoke java.exe on this class. If Java is not installed or you can't run it then the process will not start... but if it starts then it'll tell you the path to the JRE installation folder, which is what you need in order to figure out where the jvm.dll is.
There's still the problem of Java being installed but not being on your PATH. In that case, I would just report that Java could not be found and ask the user for additional input.
This is a snippet of how I did it, the location of the jvm dll will be stored in runtimeLib.
char version[255];
char runtimeLib[255];
DWORD BufferSize = 8192;
string javaKey = "SOFTWARE\\JavaSoft\\Java Runtime Environment";
if(RegGetValue(HKEY_LOCAL_MACHINE, javaKey.c_str(), "CurrentVersion", RRF_RT_ANY, NULL, (PVOID)&version, &BufferSize) != ERROR_SUCCESS)
//jre not found
javaKey += "\\";
javaKey += version;
BufferSize = 8192;
if(RegGetValue(HKEY_LOCAL_MACHINE, javaKey.c_str(), "RuntimeLib", RRF_RT_ANY, NULL, (PVOID)&runtimeLib, &BufferSize) != ERROR_SUCCESS)
//jvm.dll not found
Location of VM Library Files (jvm.dll)
For Oracle's JDK. The path within the JDK to the Java HotSpot Client VM is:
jre/bin/client/jvm.dll (on x86)
The path to the Java HotSpot Server VM is:
jre/bin/server/jvm.dll (on x86)
jre/bin/server/jvm.dll (on IA64)
Windows Registry Keys
Oracle, OpenJDK, Azul, IBM and other JDK developers may use a variety of Windows Registry Keys. For example, Java 11 appears to use the JavaSoft\JDK key, while Java 8 uses JavaSoft\Java Development Kit. Programs like Launch4j and Java Service Launcher search the registry for JVMs.
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit\{version}\JavaHome
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Plug-in\{version}\JavaHome
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\{version}\JavaHome
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\JDK\{version}\JavaHome
EDIT
# Recursively search JAVA_HOME for jvm.dll to set JVM_FILE
FOR /R %JAVA_HOME% %f IN (*) DO IF "%~nxf"=="jvm.dll" SET JVM_FILE="%~dpnxf"

Installing JDK and setting JAVA_HOME

What exactly is the purpose of JDK - running java programs or developing?
There seems to be too many packages that include java and jdk/sdk in their title. Which one should I install if I want to develop Java applications?
Who uses JAVA_HOME and what should I set it to be?
JDK is development environment. JVM is runtime environment.
You should download java installer from oracle web site or install it from repositiry manager
JAVA_HOME system variable usually is required for enterprice java software (application servers, DBs, development tools and so on). You should set JAVA_HOME variable to root directory of JDK or JVM(setting it to JDK always works, but maybe some software will run as expected with JAVA_HOME pointing to JRE). If you set JAVA_HOME right then $JAVA_HOME/bin/java -version command should pring version of java.
JRE means Java Runtime Environment. Most Java Software only needs a JRE to run.
JDK means Java Development Kit. A JDK allways includes a JRE. If you develop you most certainly allways use the JDK, since it contains source and docs of java's own Classes.
Also there is software (usually software for development) that uses tools of the JDK to run, e.g. this software needs the JDK as runtime environment (for example: ant).
JVM means Java Virtual Machine and is the program that runs your java program no matter if in JRE or JDK.
JAVA_HOME is the path to the JDK
JRE_HOME is the path to the JRE
JDK - Java Development Kit (in contrast to JRE - Java Runtime Environment).
If you don't know which version of Java you need, just get the latest (currently Java Platform (JDK) 7u5). Unless you already have a development tool, you might want the Netbeans bundle instead.
JAVA_HOME is used by some software that depends on Java - ant, which is a build tool, is one that comes to mind. It should be set to the directory which contains the bin directory, which in turn contains the java executables.

Java server jvm installation on windows 32 bit systems

I am trying to bundle java as a part of a java product that should be installed silently with a single click and are having some issues:
My installation has the following requirements:
Has no be silent and require no user input or action excpect a doubleclick on the installation file (no configuration and post install steps)
Has to setup java so that JAVA_HOME points to a Java SE installation with a server jvm
Is this at all possible to do this on a win32 system with sun java installers? I know that by default the jre does not contian a server jvm. But even when installing the jdk the public jre which is installed (and mapped to JAVA_HOME) does not contain a server jvm. In sun own README file (Sun README) they suggest copying the files:
jre\bin\server\
On Microsoft Windows platforms, the JDK includes both
the Java HotSpot(TM) Server VM and Java HotSpot Client VM.
However, the Java SE Runtime Environment for Microsoft Windows
platforms includes only the Java HotSpot Client VM. Those wishing
to use the Java HotSpot Server VM with the Java SE Runtime
Environment may copy the JDK's jre\bin\server folder to a
bin\server directory in the Java SE Runtime Environment.
But this solution is difficult to automate gracefully in a silent install. There has to be a better way to do this without repackaging the entire java distrubution. Has anyone encountered the same problem and come up with a more elegant solution?
For the past years, I manage Java like this: I download the installer, install it somewhere, package all files into a ZIP and then use that ZIP file to deploy Java anywhere. The installer will leave a lot of stuff in the registry and %WinDir%, etc. which you don't really need. This also allows me to move some files around (like the bin\server\jvm.dll or security related settings).
That way, I can even embed Java inside the application directory, independent of any already installed version of Java.
Just set JAVA_HOME in a small batch script before starting your application and you're good. You can use %~dp0 to make it completely position independent (%~dp0 expands to the path leading to the batch file).
Make your own installer.
I use inno setup compiler, works well for my purpose.
If you need the registry entries, you can export them, include them in the installer, include the files, and a little change here and there and you're done. Silent installer that configures things to the exact specifications you need.
It comes with an easy to use script wizard.
I mention a specific one because it's free. Ultimately, making your own installer is the solutions.

Categories