JAVA_HOME is not defined correctly on Ubuntu?

烈酒焚心 提交于 2019-12-04 18:03:49

问题


I am trying to install some software (Shibboleth) in Ubuntu 14.04. I already have Java 7 OpenJDK installed in /usr/lib/jvm/, and I have these lines in /usr/environment

JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64"
export JAVA_HOME

If I type echo $JAVA_HOME I correctly get /usr/lib/jvm/java-7-openjdk-amd64. However, when I try to install Shibboleth I always get Error: JAVA_HOME is not defined correctly. Cannot execute java.

Interestingly, if I type java command it works (it refers to /usr/lib/java which is a link to the right one). However, when I try to run bash bin/install.sh of Shibboleth, I get the JAVA_HOME error

I already tried setting JAVA_HOME to the jre folder with same result. Any ideas?


回答1:


Add both JAVA_HOME & PATH to your ~/.profile

export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH

And, add following to your /etc/profile.d/java.sh

JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
export JAVA_HOME
PATH=${JAVA_HOME}/bin:${PATH}
export PATH
JRE_HOME=/usr/lib/jvm/jre
export JRE_HOME
JAVA_OPTS="-XX:+AggressiveOpts -Xms256m -Xmx512m -XX:MaxPermSize=256m -XX:+DisableExplicitGC"
export JAVA_OPTS

For more info, Refer Documentation

Hope it helps.




回答2:


Instead of

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

I did

EXPORT JAVA_HOME='/usr/lib/jvm/java-1.7.0-openjdk-amd64'

Works.




回答3:


According to Your editor.

sudo vim /etc/profile

add these 2 lines at the end of the file

export JAVA_HOME="/usr/lib/jvm/java-8-oracle"  
export PATH=JAVA_HOME/bin:$PATH

Then

source /etc/profile

Check

mvn -version



回答4:


you should set the path to bin folder where java, javac files are found. In your case it might be /usr/lib/jvm/java-7-openjdk-amd64/bin




回答5:


I issue is that the install.sh script which you are running has the java path wrong.

Edit the file using nano

    sudo nano idp-install.sh

or vim editor

    vim idp-install.sh

and change the line which corresponds to java path and add the correct java path. This will solve your problem.

P.S. This solution is specific to the java path for Shibboleth installation.




回答6:


from Ubantu terminal execute:

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

to test maven run:

mvn --version

it will give output:

Maven home: /usr/share/maven
Java version: 1.7.x.xxx, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-7-openjdk-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-47-generic", arch: "amd64", family: "unix"


来源:https://stackoverflow.com/questions/34966648/java-home-is-not-defined-correctly-on-ubuntu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!