簡體   English   中英

請確保JAVA_HOME指向JDK而不是JRE

[英]Please ensure JAVA_HOME points to JDK rather than JRE

我從鏈接http://www.oracle.com/technetwork/java/javase/downloads/index.html下載了jdk-9.0.1_linux-x64_bin.tar.gz和jre-9.0.1_linux-x64_bin.tar.gz。 提取它們並將其粘貼在/ usr / local / java中。 然后編輯/ etc / profile添加

JAVA_HOME=/usr/local/java/jdk-9.0.1
JRE_HOME=/usr/local/java/jre-9.0.1
PATH=$PATH:$JRE_HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH

整個文件看起來像

# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

if [ "$PS1" ]; then
  if [ "$BASH" ] && [ "$BASH" != "/bin/sh" ]; then
    # The file bash.bashrc already sets the default PS1.
    # PS1='\h:\w\$ '
    if [ -f /etc/bash.bashrc ]; then
      . /etc/bash.bashrc
    fi
  else
    if [ "`id -u`" -eq 0 ]; then
      PS1='# '
    else
      PS1='$ '
    fi
  fi
fi

# The default umask is now handled by pam_umask.
# See pam_umask(8) and /etc/login.defs.

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi

JAVA_HOME=/usr/local/java/jdk-9.0.1
JRE_HOME=/usr/local/java/jre-9.0.1
PATH=$PATH:$JRE_HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH

然后鍵入以下命令

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk-9.0.1/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk-9.0.1/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk-9.0.1/bin/javaws" 1 


sudo update-alternatives --set java /usr/local/java/jdk-9.0.1/bin/java
sudo update-alternatives --set javac /usr/local/java/jdk-9.0.1/bin/javac
sudo update-alternatives --set javaws /usr/local/java/jdk-9.0.1/bin/javaws

source /etc/profile

reboot

現在java -version正在顯示

java version "9.0.1"
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)

之后,我嘗試安裝android studio

我收到以下消息

./studio.sh 
Java HotSpot(TM) 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
WARN: Unknown class loader: jdk.internal.loader.ClassLoaders$AppClassLoader
WARN: Unknown class loader: jdk.internal.loader.ClassLoaders$PlatformClassLoader
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.intellij.util.lang.UrlClassLoader (file:/home/user/Downloads/Android/android-studio/lib/util.jar) to field java.lang.ClassLoader.parallelLockMap
WARNING: Please consider reporting this to the maintainers of com.intellij.util.lang.UrlClassLoader
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

JDK Required: 'tools.jar' seems to be not in Studio classpath.
Please ensure JAVA_HOME points to JDK rather than JRE.

嘗試更改設置PATH變量的行,從

PATH=$PATH:$JRE_HOME/bin:$JAVA_HOME/bin

PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin

這將使JDK優先於JRE。

我建議您卸載JRE安裝並僅使用JDK安裝。 JDK包含JRE中存在的所有內容。 同時安裝這兩種方法都浪費了磁盤空間,並可能導致類似您遇到的問題。

卸載JRE時,請記住要更新環境變量。

還值得注意的是,通過像這樣設置PATH,就可以避免使用“ alternatives”選擇器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM