How to find Java outside the JavaSoft registry - Advanced Installer Community
murtlap
Posts: 6
Joined: Wed Dec 02, 2020 10:04 am

How to find Java outside the JavaSoft registry

Hi.

I am using Advanced Installer 17.6 to install a Java application and to create an executable Java wrapper. Therefore it is required that the machine installing and running this application has Java installed, but it is not desirable that Java is installed as part of the application. Hence the installer searches for Java installations on the machine and if not found it warns the user, but finishes the installation of the Java application. Upon start, the Java application will prompt for a path to the Java installation and writes this path to the JRE Path of the .ini file of the application.

Now to my problem. Installers and executables built with Advanced Installer seem to only search for Java installations in the JavaSoft registry (after looking for a JRE Path in the .ini file of the application, https://www.advancedinstaller.com/user- ... ncher.html). However, various Java installations are not written to the JavaSoft registry. This can e.g. happen when installing Java from a .zip file.

I had some considerations that it might be possible to search for Java on PATH, in other registries than JavaSoft, or in other places (and even ask the user, which version should be used), but then the chosen Java installation path still has to be written to the JRE Path of the .ini file. This solution kind of hardcodes the Java path, which is causing issues, if the user wants to e.g. upgrade Java. So, I would like to know if there is a possibility to find installed Java installations, which are not written to the JavaSoft registry key? I mean in a more flexible and reliable way, which does not require that Java is installed/pointed at in a specific place?

Best regards,
Anna
Catalin
Posts: 7852
Joined: Wed Jun 13, 2018 7:49 am

Re: How to find Java outside the JavaSoft registry

Hello Anna,
Now to my problem. Installers and executables built with Advanced Installer seem to only search for Java installations in the JavaSoft registry (after looking for a JRE Path in the .ini file of the application, https://www.advancedinstaller.com/user- ... ncher.html).
If possible, could you please give me some more details about this?

When adding a new java product, in the .INI file I can only see three entries: Main Class, Minimum Version and Maximum Version. There is no entry related to the path of the JRE.
So, I would like to know if there is a possibility to find installed Java installations, which are not written to the JavaSoft registry key? I mean in a more flexible and reliable way, which does not require that Java is installed/pointed at in a specific place?
I'm afraid I am not aware of any full-proof method to achieve that.

After a bit of research, I have found that you can check whether Java is installed or not by running the following in a command prompt:

Code: Select all

java -version
So perhaps I am thinking we can proceed as it follows:

- have a custom action

- from that custom action, launch cmd.exe with the above arguments

- verify the return code

However, even this method is somehow restricted because, in order to use the above, Java must be added to the PATH environment variable, otherwise it will always return an error.

Hope this helps somehow! :?

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
murtlap
Posts: 6
Joined: Wed Dec 02, 2020 10:04 am

Re: How to find Java outside the JavaSoft registry

Hi Catalin,

First of all, thank you for the response!

I am a bit unsure, what you are asking for. Is it that I state that the JavaSoft registry is searched or the fact that the installer (and the executable Java wrapper) looks for the JRE Path in the .ini file?

Assuming the latter, the JRE Path is not written to the .ini file by default, but when Java is not found in the JavaSoft registry the GUI of the executable Java Wrapper will prompt the user to specify a path to a Java installation (as described loosly on the site I linked to earlier). This path is saved in the 'JRE Path' of the 'Java Runtime Environment' section in the .ini file.

I have considered your proposed solution. I think it is possible to require that Java is on the PATH and it could possibly provide a dynamic way for the installer to find a Java installation, which is not written to the JavaSoft registry. But in order to enable the executable Java wrapper to use this path, I cannot see how to circumvent "hardcoding" the path somewhere, e.g. in the JRE Path of the .ini file. Hence it will not be possible to upgrade Java later without requiring the user to change the hardcoded path.

What I am looking for is a dynamic (evaluated at execution time) way of finding Java, which does not require the Java installation to be written to the JavaSoft registry. I could for example accept to require that Java is on the PATH, but I would really like it to be evaluated at execution time in order to be able to e.g. upgrade Java.

Feel free to ask again, if my issues are still unclear.

Best regards,
Anna
Catalin
Posts: 7852
Joined: Wed Jun 13, 2018 7:49 am

Re: How to find Java outside the JavaSoft registry

Hello Anna,

You are always welcome!
I am a bit unsure, what you are asking for. Is it that I state that the JavaSoft registry is searched or the fact that the installer (and the executable Java wrapper) looks for the JRE Path in the .ini file?

Assuming the latter, the JRE Path is not written to the .ini file by default, but when Java is not found in the JavaSoft registry the GUI of the executable Java Wrapper will prompt the user to specify a path to a Java installation (as described loosly on the site I linked to earlier). This path is saved in the 'JRE Path' of the 'Java Runtime Environment' section in the .ini file.
It was indeed the latter.

It looks like I did not pay enough attention when reading the provided article. I apologize for that!
What I am looking for is a dynamic (evaluated at execution time) way of finding Java, which does not require the Java installation to be written to the JavaSoft registry. I could for example accept to require that Java is on the PATH, but I would really like it to be evaluated at execution time in order to be able to e.g. upgrade Java.
Unfortunately, I am afraid I am not aware of any way of finding whether Java is installed or not that would meet your requirements.

To be fully honest with you, I am not even sure there is a full-proof method to achieve that (I might be wrong, though).

According to this article (from Oracle): Installing the Java Runtime Environment (JRE), the ways of finding whether Java JRE is installed are quite limited.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
murtlap
Posts: 6
Joined: Wed Dec 02, 2020 10:04 am

Re: How to find Java outside the JavaSoft registry

Hi Catalin,

I know this is not an easy issue to deal with, and maybe it is not even possible to solve. Without knowing if it feasible in Advanced Installer, I guess it is quite common for applications to respect the JAVA_HOME environment variable.

Nevertheless, I appreciate your effort and help very much!

Best regards,
Anna
Catalin
Posts: 7852
Joined: Wed Jun 13, 2018 7:49 am

Re: How to find Java outside the JavaSoft registry

Hello Anna,

You are always welcome!

I am sorry we did not quite manage to solve this.

Please let me know if you have any other questions and I will be glad to assist.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”