eclipse JRE系统库缺少tools.jar

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13544196/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 19:28:41  来源:igfitidea点击:

JRE system library missing tools.jar

eclipseclasspathjava

提问by Deyan Ulevinov

I am using Ubuntu 12.04(LTS). In my project in Eclipse I need to use the com.sun.tools.attach package. However, my JRE system library does not include the tools.jar file which contains the package.

我正在使用 Ubuntu 12.04(LTS)。在我的 Eclipse 项目中,我需要使用 com.sun.tools.attach 包。但是,我的 JRE 系统库不包含包含该包的 tools.jar 文件。

I tried installing different JREs and JDKs for both Java 6 and 7. What I noticed is that some of them have the mentioned jar file in their libs folder but Eclipse still fails to include it in my classpath upon selection of the JRE. Referencing tools.jar directly solves the problem but since this is a shared project I am not allowed to modify the classpath and thus this is not a viable solution for me.

我尝试为 Java 6 和 7 安装不同的 JRE 和 JDK。我注意到其中一些在他们的 libs 文件夹中有提到的 jar 文件,但 Eclipse 在选择 JRE 后仍然无法将它包含在我的类路径中。引用 tools.jar 直接解决了问题,但由于这是一个共享项目,我不允许修改类路径,因此这对我来说不是一个可行的解决方案。

My friend is using a MAC with the same version of Eclipse and the default JRE and does not have this problem. What we found out is that for him tools.jar is part of classes.jar which is not the case in my setup (I don't have classes.jar whatsoever).

我朋友用的是同版本Eclipse和默认JRE的MAC,没有这个问题。我们发现对他来说,tools.jar 是 classes.jar 的一部分,这在我的设置中并非如此(我没有 classes.jar 任何东西)。

What do you think might be the source of this problem? Any advice would be greatly appreciated.

你认为这个问题的根源是什么?任何建议将不胜感激。

Thanks guys!!!

谢谢你们!!!

回答by rlegendi

The issue is that the JDK contains the tools.jar file (neither of the JREs do).

问题是 JDK 包含 tools.jar 文件(JRE 都不包含)。

It is easy to solve the problem, you have to specify the default runtime environment to use either for the project or for the whole workspace. Change that to any of the installed JDKs.

解决这个问题很容易,您必须指定用于项目或整个工作区的默认运行时环境。将其更改为任何已安装的 JDK。

The easiest way is probably going to Window --> Preferences --> Java --> Installed JREs, and selecting the JDK instead of the JRE. All the projects use this setting by default.

最简单的方法可能是转到Window --> Preferences --> Java --> Installed JREs,然后选择 JDK 而不是 JRE。默认情况下,所有项目都使用此设置。

回答by pilot

I had exactly the same problem on Ubuntu 12.10 and in my case managed to solve it by adding a reference to the current Java binaries folder to my PATHvariable.

我在 Ubuntu 12.10 上遇到了完全相同的问题,就我而言,通过向我的PATH变量添加对当前 Java 二进制文件文件夹的引用来设法解决它。

PATH="$PATH:/usr/local/java/current/bin"

Or

或者

PATH="$PATH:$JAVA_HOME/bin"

Just edit either .profileor .bash_profilein your /home/<user>folder and you should be fine. If these files doesn't exist just create one of them.

只需编辑.profile.bash_profile在您的/home/<user>文件夹中进行编辑,您应该没问题。如果这些文件不存在,只需创建其中之一。

Note: make sure your are using JDK and not JRE

注意:确保您使用的是 JDK 而不是 JRE