Search code examples
jbossenvironment-variablesjboss7.xjava-home

How to get JBoss 7.1.3 to use my $JAVA_HOME environment varaible?


I'm using Mac 10.9.5 with JBoss 7.1.3.Final. I am launching JBoss through the termianl (bash shell), like so

Daves-MacBook-Pro:core davea$ cd $JBOSS_HOME/bin
Daves-MacBook-Pro:bin davea$ sudo sh standalone.sh

Within the shell, I can see that $JAVA_HOME is defined ...

Daves-MacBook-Pro:bin davea$ echo $JAVA_HOME
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

However, JBoss is not picking up this environment variable (it is using a Java 8 installation that I also have on my machine), forcing me to uncomment the following line in my $JBOSS_HOME/bin/standalone.conf file ...

JAVA_HOME="/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home"

Although this is straightforward, I would prefer a solution that is more automatic. Does anyone know what I have to do to get JBoss to recognize the $JAVA_HOME environment variable I have set in my shell without my having to hard-code the value in a Jboss config?

Edit:

(In response to the commnent posted) Keep in mind I’m doing all this from the same shell. So here is where I have shown I have the $JAVA_HOME environment var defined …

Daves-MacBook-Pro:bin davea$ echo $JAVA_HOME
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

Then I edit my $JBOSS_HOME/standalone/bin/standalone.conf file in the way you suggest …

echo JAVA_HOME=$JAVA_HOME
echo "DONe with echo"
#JAVA_HOME="/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home"

and when I re-run the startup script, this is what prints out …

JAVA_HOME=
DONe with echo

Solution

  • If you really want to use sudo, you have to add the -E parameter to preserve the environment variables.