I'm using Visual Studio to make an msi that installs a particular file into the location where JRE is installed. I cannot provide the default path (C:\Program files\Java) since the path could be relative as the user could install JRE in any drive other than C:. How do I do this? Is there a way in which I can locate the JRE path from registry and use this path as the location for installation?
-
Have a look here: http://stackoverflow.com/questions/3930383/jre-installation-directory-in-windows Actuall the sequence is quite simple: find the folder and initialize your JRE directory (all paths under this directory are relative) – Vadim Sep 15 '15 at 10:32
-
@Vadim What if I need to install the file into a directory within JRE? How do I give the entire relative path to the msi? – Kiran Ballal Sep 15 '15 at 10:42
-
Just define a Directory with id for example "JRE_FOLDER" as a child for TARGETDIR and use JRE_FOLDER as DirectoryId for your components and as parent for all your subfolders. When you'll define JRE_FOLDER with a real value, all paths will be automatically resolved. – Vadim Sep 15 '15 at 10:47
-
@Vadim Sorry for pestering you again. I'm a beginner. I'm writing a cpp code, within the same project, that displays the required path with a variable. Any chance I can take the value from this cpp file and include it as the default location for msi installer? – Kiran Ballal Sep 15 '15 at 11:39
1 Answers
Basically you do a registry search and use the the result for a custom folder:
According to that link that was given you: JRE installation directory in Windows the registry location is HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment in the the JavaHome item. So in the VS Setup Project do a Launch Conditions-> Search Target Machine with that registry key. Right-click Search Target Machine, add registry search, and in the properties pick a name, an uppercase Property such as JREPATH in Property, use that that key in the RegKey, vsdrrHKLM in ther Root, and JavaHome in the Value.
When that registry search runs it return that path, so in File System on Target Machine view, right click that node and choose Add Custom Folder. In the properties of that folder, you want JREPATH in Property, that's the main thing. Now you have the custom folder, add your file to that folder just like you added files to Application Folder.
That should get you there - the main issue is that it's not clear to me whether that registry location is 32-bit or 64-bit location, and the VS registry search in the 64-bit registry is broken, so that would require an extra fix. That should get you there. Ifyou take a verbose log during the install you can see if that registry search is working. Use msiexec /i /L*vx
-
What if we have multiple versions of JRE installed in the system? In that case, I want to install the file into /lib/ext folder of the latest version of java. How would I get the JavaPath of the Current Version (which means the latest installed version) from the registry ? – Kiran Ballal Sep 16 '15 at 05:34
-
Requiring the latest version would have been a good thing to say in the original question. So you cannot do that within a Visual Studio setup program because you can't run any code early in the install to enumerate the installed JRE versions and use the latest. VS setups have limited functionality compared to other setup tools. You could do that with a program you run before the MSI install - you'd read those registry entries and find the required path and write that to your own registry entry that the install would use the way I described. – PhilDW Sep 16 '15 at 17:34