0

I'm trying to install tomcat7 using Ansible. After installation, when restarting service, I'm getting errors because there is no java_home set :

no JDK or JRE found - please set JAVA_HOME

I know I can set the java_home value in /etc/default/tomcat7, but what I'm looking for, is why JAVA_HOME is not set by default to the only installed Java and we have to do it manually before starting any Java application/server :

update-alternatives --config java
There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java Nothing to configure.

I'm using trusty 14.04 and openjdk8

Dady09
  • 649
  • 2
  • 7
  • 10
  • Related: http://stackoverflow.com/questions/2655641/make-java-home-easily-changable-in-ubuntu?rq=1 – Mark Rotteveel Apr 18 '17 at 16:35
  • ubuntu java installation packages don't set JAVA_HOME by default. What kind of answer to this question do you expect to get? – eis Apr 18 '17 at 16:36

2 Answers2

1

Your JAVA_HOME would appear to be /usr/lib/jvm/java-8-openjdk-amd64, to set it persistently as root create /etc/profile.d/jdk.sh with

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64

and make it executable,

sudo chmod 755 /etc/profile.d/jdk.sh

You need to logout and log back in for that to take effect, or you can execute

$ export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64

And it should work as expected.

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
0

go to home directory and press ctrl+h and show hidden files then create .bash_aliases file into home folder.

and write two line into .bash_aliases file. /home/hadoop/install/jdk1.8.0_92 by your current jdk path. then restart terminal and check java -version, you get the version details.

export JAVA_HOME=/home/hadoop/install/jdk1.8.0_92
export PATH=$JAVA_HOME/bin:$PATH
Anshul Sharma
  • 3,432
  • 1
  • 12
  • 17