Java 没有 sudo,IntelliJ 找不到 tools.jar
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24992038/
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
IntelliJ can't find tools.jar without sudo
提问by Patrick Collins
I'm trying to run IntelliJ on Ubuntu 14.04. I've read this questionbut the solutions don't apply -- I've definitely got the JDK installed rather than the JRE. When I try to run idea.sh
, I get the error message:
我正在尝试在 Ubuntu 14.04 上运行 IntelliJ。我读过这个问题,但解决方案不适用——我肯定安装了 JDK 而不是 JRE。当我尝试运行时idea.sh
,我收到错误消息:
'tools.jar' seems to be not in IDEA classpath. Please ensure JAVA_HOME points to JDK rather than JRE.
“tools.jar”似乎不在 IDEA 类路径中。请确保 JAVA_HOME 指向 JDK 而不是 JRE。
JAVA_HOME
is set to /etc/java-7-openjdk
. Eclipse (in the form of Eclim) has no problem finding it. javac -version
prints javac 1.7.0_55
.
JAVA_HOME
设置为/etc/java-7-openjdk
。Eclipse(以 Eclim 的形式)可以毫无问题地找到它。javac -version
打印javac 1.7.0_55
。
However, if I run sudo ./idea.sh
, IntellJ launches fine. What am I missing?
但是,如果我运行sudo ./idea.sh
,IntellJ 启动正常。我错过了什么?
采纳答案by Patrick Collins
It turns out JAVA_HOME
was set wrong, I needed to set it to:
原来JAVA_HOME
设置错了,我需要将它设置为:
/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
to get it working. I'm not sure why this hadn't caused me any problems before.
让它工作。我不确定为什么这之前没有给我带来任何问题。
EDIT: This setting makes Maven angry (although Maven via IntelliJ works fine). For future readers, I believe the correct setting is:
编辑:这个设置让 Maven 生气(虽然 Maven 通过 IntelliJ 工作正常)。对于未来的读者,我相信正确的设置是:
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre/
回答by joe
I had the exact same problem half an hour ago. Took me exactly that half hour to fix it, this is how it worked for me:
半小时前我遇到了完全相同的问题。我花了半个小时才修复它,这对我来说是这样的:
Short version:add
简短版本:添加
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
to your .bashrc
, source it and you are fine.
到你的.bashrc
,来源它,你很好。
Explanation:
解释:
After installing the JDK in Ubuntu there are multiple folders on your disk. The root folder is
在 Ubuntu 中安装 JDK 后,磁盘上有多个文件夹。根文件夹是
/usr/lib/jvm/java-7-openjdk-amd64/
under which the aforementioned /jre
-Folder resides.
The whole problem is, that the jre/lib
-Folder does not contain the tools.jar
- File searched by the IDE.
Only the /usr/lib/jvm/java-7-openjdk-amd64/lib
- Folder does.
上述/jre
-Folder 所在的文件夹。整个问题是,jre/lib
-Folder 不包含tools.jar
IDE 搜索的- 文件。只有/usr/lib/jvm/java-7-openjdk-amd64/lib
- 文件夹可以。
To get everything working you have to specify /usr/lib/jvm/java-7-openjdk-amd64
as JAVA_HOME
.
要使一切正常,您必须指定/usr/lib/jvm/java-7-openjdk-amd64
为JAVA_HOME
.
Setting /usr
as your JAVA_HOME
wont solve the problem as that is symlinked to /etc/alternatives
which is symlinked to our old friend the /jre
-Folder.
设置/usr
为您JAVA_HOME
不会解决问题,因为它是符号链接到/etc/alternatives
哪个/jre
符号链接到我们的老朋友 - 文件夹。
I hope this helped you!
我希望这对你有帮助!
回答by Mohammad-Hossein Jamali
you can change your current java version as follows
您可以按如下方式更改当前的 Java 版本
alternatives --config java
alternatives --config javac
but before them you need to install your newly installed JDK in alternatives properly:
但在它们之前,您需要正确安装新安装的 JDK:
alternatives --install /usr/bin/java java [new-jdk-path]/bin/java 120 --slave /usr/bin/rmiregistry rmiregistery [new-jdk-path]/bin/rmiregistry --slave /usr/bin/keytool keytool [new-jdk-path]/bin/keytool --slave /usr/lib/tools.jar tools.jar [new-jdk-path]/lib/tools.jar
alternatives --install /usr/bin/javac javac [new-jdk-path]/bin/javac 120 --slave /usr/bin/jar jar [new-jdk-path]/bin/jar --slave /usr/bin/rmic rmic [new-jdk-path]/bin/rmic
回答by Esmaeil MIRZAEE
In the 64 bit Debian 7, I solved the problem by adding this two lines of code in idea.sh under the /path/to/intellij-folder/bin/
在64位Debian 7中,我通过在idea.sh中的/path/to/intellij-folder/bin/下添加这两行代码解决了这个问题
export IDEA_JDK=/path/to/jdk/
export JAVA_HOME=/path/to/jre
And I hope it will solve the problem in Ubuntu.
我希望它能解决 Ubuntu 中的问题。