Java 所选目录不是 JDK 的有效主目录 - Ubuntu 上的 Intellij IDEA
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30116439/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Selected directory is not a valid home for JDK - Intellij IDEA on Ubuntu
提问by Andrew Schade
After installing Intellij Idea 14, with OracleJDK 1.8 u25 (64 bit) on my 14.04 Ubuntu system, I cannot configure the Java SDK to use any JDK. When I navigate to Module Settings->SDK and click configure SDK, the add button, and then select /usr/java/jdk1.8.0_25
in the dialog, I get an error popup stating that "The selected directory is not a valid home for JDK."
在我的 14.04 Ubuntu 系统上使用 OracleJDK 1.8 u25(64 位)安装 Intellij Idea 14 后,我无法将 Java SDK 配置为使用任何 JDK。当我导航到“模块设置”->“SDK”并单击“配置 SDK”、“添加”按钮,然后/usr/java/jdk1.8.0_25
在对话框中选择时,我收到一个错误弹出窗口,指出“所选目录不是 JDK 的有效主目录”。
I've checked the contents of the directory, which contains a bin
folder with both java
and javac
inside, a lib
folder and a jre
folder.
我检查了目录,其中包含的内容bin
与文件夹都java
和javac
内,一个lib
文件夹,一个jre
文件夹。
I've tried selecting each of those in turn, to no avail, which I expected.
我试过依次选择每一个,但无济于事,这是我所期望的。
采纳答案by Andrew Schade
Evan Knowles posted a link to https://askubuntu.com/questions/130186/what-is-the-rationale-for-the-usr-directory. It provided me with the solution to the problem.
Evan Knowles 发布了一个链接到https://askubuntu.com/questions/130186/what-is-the-rationale-for-the-usr-directory。它为我提供了解决问题的方法。
Instead of using the JDK at /usr/java/jdk1.8.0_25
, I instead used the JDK at /usr/local/java/jdk1.8.0_25
. The reasons that this works rather than the other are explained in detail within the link.
/usr/java/jdk1.8.0_25
我没有在 处使用 JDK ,而是在 处使用了 JDK /usr/local/java/jdk1.8.0_25
。链接中详细解释了这种方式而不是其他方式的原因。
回答by Francesco Borzi
I had the same problem, in my case I wasn't able to select any of the "openjdk" directories under /usr/lib/jvm/
, I solved with:
我遇到了同样的问题,在我的情况下,我无法选择 下的任何“ openjdk”目录/usr/lib/jvm/
,我解决了:
sudo apt-get install openjdk-8-jdk
sudo apt-get install openjdk-8-jdk
When restarting intellij it will find the path to the jdk automatically.
重新启动intellij 时,它会自动找到jdk 的路径。
回答by vdegenne
For the ones who run into this problem even though you select the right directory under /usr/lib/jvm
, there is something you should know : The directories under /usr/lib/jvm
are created when your system installs the minimum set of java tools. But it doesn't mean you have the development files available. You need to install the development files :
对于那些即使在 下选择了正确的目录也遇到此问题的人/usr/lib/jvm
,您应该知道一些事情:/usr/lib/jvm
当您的系统安装最少的 Java 工具集时,将创建下的目录。但这并不意味着您拥有可用的开发文件。您需要安装开发文件:
sudo apt-get install java-1.8.0-openjdk-devel
After installing this package, try to select the directory again and it should work.
安装此软件包后,再次尝试选择目录,它应该可以工作。
回答by Imran
I came across this error because I did not have JAVA_HOME
set.
我遇到了这个错误,因为我没有JAVA_HOME
设置。
Adding export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
(for openjdk 11 in my case) and export PATH=$JAVA_HOME/bin:$PATH
to my ~/.bashrc and then running source ~/.bashrc
solved the problem for me.
添加export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
(在我的情况下为 openjdk 11)和export PATH=$JAVA_HOME/bin:$PATH
我的 ~/.bashrc 然后运行source ~/.bashrc
为我解决了这个问题。