After checking for a valid Java version, I would like to set the Environment Variable in Windows to the folder where Java is located.

For instance: JAVA_HOME = C:Program FilesJavajdk1.7.0_11

Is a variable available for just that folder path? If not how would I go about detecting that since I can't hardcode that folder path because of so many Java versions.

Many thanks

asked 14 Jan '13, 14:59

Matthew%20Prinvale's gravatar image

Matthew Prin...
1223
accept rate: 0%


If you are using the <autodetectjava>, it will define the variable ${java_executable}. Using that, you can get java_home as:

<dirName path="${java_executable}" variable="java_bin_dir"/>
<dirName path="${java_bin_dir}" variable="java_home"/>

And then set the environment variable:

<addEnvironmentVariable name="JAVA_HOME" value="${java_home}"/>
link

answered 14 Jan '13, 16:39

juanjo's gravatar image

juanjo ♦♦
5.8k413
accept rate: 23%

Thanks for the help. I will give this a try and see if I can get it to work.

(14 Jan '13, 16:51) Matthew Prin...

Thanks again for the help, I tried this and it almost worked. The only issue is it's reading it as C:/path/dir

and it should be C:pathdir

How to swap?

(15 Jan '13, 13:56) Matthew Prin...

back slashes didn't show up in comment ""

(15 Jan '13, 13:59) Matthew Prin...

You can change them to backslashes using:

 <setInstallerVariableFromRegEx>
    <name>backslash_path</name>
    <pattern>/</pattern>
    <substitution>\</substitution>
    <text>${forwardslash_path}</text>
 </setInstallerVariableFromRegEx>
(15 Jan '13, 14:17) juanjo ♦♦
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×176
×41
×40
×26
×14
×3

Asked: 14 Jan '13, 14:59

Seen: 2,462 times

Last updated: 15 Jan '13, 14:17