eclipse m2eclipse 无法定位 C:\Program Files\Java\jre6\..\lib\tools.jar
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10367286/
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
m2eclipse is unable to locate C:\Program Files\Java\jre6\..\lib\tools.jar
提问by mvieghofer
I have a problem, concerning the jdk/jre usage of my eclipse. I know that this question was asked and answered a lot of times here and I researched what could be wrong for quite a while. I actually didn't find anything so I'm going to ask you again. Maybe I'm missing something (if yes, I hope it's not to embarrasing :)
我有一个问题,关于我的 eclipse 的 jdk/jre 用法。我知道这个问题在这里被问过和回答过很多次,我研究了很长一段时间可能出现的问题。我实际上没有找到任何东西,所以我要再问你一次。也许我错过了一些东西(如果是的话,我希望这不会让人尴尬:)
My problem is, that when I'm running mvn clean install I get an error which says that the m2eclipse plugin is "Unable to locate the Javac Compiler in: C:\Program Files\Java\jre6..\lib\tools.jar".
我的问题是,当我运行 mvn clean install 时,我收到一条错误消息,指出 m2eclipse 插件是“无法在以下位置找到 Javac 编译器:C:\Program Files\Java\jre6..\lib\tools.jar ”。
First thing I checked was if the right JRE was configured in eclipse. So I switched into Window > Preferences > Java > Installed JREs and checked if the selected jre is the jre inside my jdk folder. This was the case.
我检查的第一件事是是否在 eclipse 中配置了正确的 JRE。所以我切换到 Window > Preferences > Java > Installed JREs 并检查所选的 jre 是否是我的 jdk 文件夹中的 jre。情况就是这样。
I checked the eclipse.ini and added a -vw flag to it. It now looks like:
我检查了 eclipse.ini 并添加了一个 -vw 标志。现在看起来像:
-startup
plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.100.v20110502
-product
org.eclipse.epp.package.java.product
--launcher.defaultAction
openFile
--launcher.XXMaxPermSize
256M
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
-vm
"%JAVA_HOME%\bin\javaw.exe"
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms40m
-Xmx384m
The %JAVA_HOME% is resolved to C:\Program Files\Java\jdk1.6.0_24. Since it contains a space I surrounded the vw path with quotes. To check if the path is really correct I tried
%JAVA_HOME% 被解析为 C:\Program Files\Java\jdk1.6.0_24。由于它包含一个空格,我用引号将 vw 路径括起来。为了检查路径是否真的正确,我试过
C:\Windows\System32>echo %JAVA_HOME%
C:\Program Files\Java\jdk1.6.0_24
which tells me that it is correct. I also tried to pass the -vw option when eclipse is started. So the command to start eclipse was then
这告诉我这是正确的。我还尝试在 eclipse 启动时传递 -vw 选项。所以启动eclipse的命令是
D:\Programs\eclipse\eclipse.exe -vm "%JAVA_HOME%\bin\javaw.exe"
I also tested if there is a difference when I use the %JAVA_HOME% notation or if I writed the full path (it makes no difference).
我还测试了当我使用 %JAVA_HOME% 符号时是否有区别,或者我是否写了完整路径(没有区别)。
The configuration of eclipse, which I get when I go to Help > About Eclipse > Installation Details > Configuration, looks like that:
当我转到“帮助”>“关于 Eclipse”>“安装详细信息”>“配置”时获得的 eclipse 配置如下所示:
__wbp.gwt.useWebKit=true
awt.toolkit=sun.awt.windows.WToolkit
veclipse.application=org.eclipse.ui.ide.workbench
eclipse.buildId=M20120208-0800
eclipse.commands=-os
win32
-ws
win32
-arch
x86_64
-showsplash
-launcher
D:\Programs\eclipse\eclipse.exe
-name
Eclipse
--launcher.library
D:\Programs\eclipse\plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.100.v20110 502\eclipse_1406.dll
-startup
D:\Programs\eclipse\plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar
--launcher.overrideVmargs
-exitdata
3e30_64
-product
org.eclipse.epp.package.java.product
-vm
C:\Program Files\Java\jdk1.6.0_24\bin\javaw.exe
eclipse.home.location=file:/D:/Programs/eclipse/
eclipse.launcher=D:\Programs\eclipse\eclipse.exe
eclipse.launcher.name=Eclipse
[email protected]/../p2/
eclipse.p2.profile=epp.package.java
eclipse.product=org.eclipse.epp.package.java.product
eclipse.startTime=1335643108722
eclipse.vm=C:\Program Files\Java\jdk1.6.0_24\bin\javaw.exe
eclipse.vmargs=-Dosgi.requiredJavaVersion=1.5
-Xms40m
-Xmx384m
-XX:MaxPermSize=256m
[...]
I also tried to use the javaw.exe that is located in %JAVA_HOME%\jre\bin\ which also doesn't change anything.
我还尝试使用位于 %JAVA_HOME%\jre\bin\ 中的 javaw.exe,它也不会改变任何东西。
One thing that is a little bit strange is, that if I delete the reference to the jre, the one that is not included in jdk, in Window > Preferences > Java > Installed JREs I get an error which says "The specified JRE installation does not exist".
有点奇怪的一件事是,如果我删除对 jre 的引用,即未包含在 jdk 中的引用,则在 Window > Preferences > Java > Installed JREs 中,我收到一条错误消息,指出“指定的 JRE 安装没有不存在”。
Does anyone have an idea what I'm doing wrong? I think I tried anything to make it work and according to the other articles I found I'm doing it right.
有谁知道我做错了什么?我想我尝试了任何方法来使它工作,根据其他文章我发现我做得对。
Btw: I did some Maven "Update Project Dependencies" and "Update Dependencies" which work, so I did not get any error there. The only thing, I did not do is to restart my computer...
顺便说一句:我做了一些 Maven “更新项目依赖项”和“更新依赖项”的工作,所以我没有在那里得到任何错误。唯一的事情,我没有做的是重新启动我的电脑......
采纳答案by mvieghofer
I figured out a workaround that seems to work. It's not really that what I hoped to be a solution but at least I can use maven now.
我想出了一个似乎有效的解决方法。这并不是我希望成为的解决方案,但至少我现在可以使用 maven。
I created a new folder on the same level in the file system as the jdk and the jre folders are. I called it lib and copied the tools.jar file form the jdk into it.
我在文件系统中创建了一个与 jdk 和 jre 文件夹处于同一级别的新文件夹。我称它为 lib 并将来自 jdk 的 tools.jar 文件复制到其中。
Additionally I switched from the "normal" eclipse for java SE to the eclipse for Java EE (I'm using EJBs). The version of eclipse is the one we got from university so i don't know if a plugin is installed which I missed to install on my (java SE) eclipse.
此外,我从 Java SE 的“普通”日食切换到 Java EE 的日食(我使用的是 EJB)。eclipse 的版本是我们从大学得到的版本,所以我不知道是否安装了一个插件,我错过了在我的(java SE)eclipse 上安装的插件。
Now It seems to work but if anybody has a solution that might solve that problem in a more elegant way please let me know.
现在它似乎有效,但如果有人有可能以更优雅的方式解决该问题的解决方案,请告诉我。
回答by m.ali.khan.5049
- Go to Windows --> Installed JREs
- select the installed JRE and click edit
- change the JRE home directory to PATH_TO_YOURJDK\jre (previously it would be PATH_TO_YOUJRE)
- this works for me
- 转到 Windows --> 已安装的 JRE
- 选择已安装的 JRE 并单击编辑
- 将 JRE 主目录更改为 PATH_TO_YOURJDK\jre(以前是 PATH_TO_YOUJRE)
- 这对我有用
回答by peter.murray.rust
See this answer. It suggests that you need to set your PATH to point to the Java bin directory. In my own case this is set:
看到这个答案。它建议您需要将 PATH 设置为指向 Java bin 目录。在我自己的情况下,这是设置:
D:\workspace>echo %PATH%
C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;
C:\Windows;C:\Windows\System32\Wbem; ...
C:\Program Files\Java\jdk1.7.0_02\bin; ...
回答by styler1972
EDIT: You mentioned you have the JRE in your JDK referenced in your build path. Well did you notice that tools.jar is NOTin this JRE folder either? tools.jar is contained in the /lib folder only. Not the JRE inside the JDK.
编辑:您提到在构建路径中引用了 JDK 中的 JRE。那么有没有注意到的tools.jar是不是在这个文件夹JRE要么?tools.jar 仅包含在 /lib 文件夹中。不是 JDK 中的 JRE。
This kept popping up for me in my project as well. For whatever reason, Eclipse keeps telling me it's unable to locate tools.jar. I have fixed it a few time for this project and tonight it came back. Below is how I ended up fixing it once and for all.
这也在我的项目中不断出现。无论出于何种原因,Eclipse 一直告诉我它无法找到 tools.jar。我已经为这个项目修复了几次,今晚它又回来了。以下是我最终一劳永逸地修复它的方式。
The reason is that you have JRE6 in your included libraries in your Java Build Path. However tools.jar is not included in any JRE, you need to import tools.jar from your JDK.
原因是您在 Java 构建路径中包含的库中有 JRE6。但是,tools.jar 不包含在任何 JRE 中,您需要从 JDK 中导入 tools.jar。
By simply going to Properties for -> Java Build path -> Libraries (Tab) -> Add External JARs.. and choosing your JDKs tools.jar file in the /lib folder, it fixes the problem. See the image below.
只需转到 Properties for -> Java Build path -> Libraries (Tab) -> Add External JARs.. 并在 /lib 文件夹中选择 JDKs tools.jar 文件,即可解决问题。见下图。
回答by Ville Myrskyneva
I notice this is already an old question, but there is a better solution for this. First of all, Eclipse ask "Installed JREs", but actually you should provide the JDK here. Like Styler kind of mentioned, but instead of importing the tools.jar separatedly just define the JDK in "Installed JREs". Then it will find everything there is needed from "basic java" without extra imports to build path (also you should not move anything to or from the JDK folder, this can break the portability of the software). Also notice that when selecting "project" > "Java Compiler" there is an option: "Enable project specific settings". If you have this option selected, it may have a different "JRE" specified to be used than what you have in "Window" > "Preferences" > "Java" > "Installed JREs" selected as default.
我注意到这已经是一个老问题了,但是有一个更好的解决方案。首先,Eclipse 会询问“Installed JREs”,但实际上您应该在这里提供 JDK。就像提到的 Styler 一样,但不是单独导入 tools.jar,而是在“已安装的 JRE”中定义 JDK。然后它会从“basic java”中找到所有需要的东西,而无需额外的导入来构建路径(你也不应该将任何东西移入或移出 JDK 文件夹,这会破坏软件的可移植性)。Also notice that when selecting "project" > "Java Compiler" there is an option: "Enable project specific settings". 如果您选择了此选项,则它可能指定要使用的“JRE”与您在“窗口”>“首选项”> 中的不同
回答by Damian Leszczyński - Vash
The problem is in definition of your JAVA_HOME
问题在于你的定义 JAVA_HOME
C:\Windows\System32>echo %JAVA_HOME%
C:\Program Files\Java\jdk1.6.0_24
When it should be
什么时候应该
C:\Windows\System32>echo %JAVA_HOME%
C:\Program Files\Java\jdk1.6.0_24\jre
The variable JAVA_HOME should point to Java Runtime directory.
变量 JAVA_HOME 应该指向 Java 运行时目录。
回答by user4693006
Below are the list of steps that had helped me to solve the issue.
以下是帮助我解决问题的步骤列表。
STEP 1:"Properties"(window):
第 1 步:“属性”(窗口):
Right-Click on your project->Properties->Java Build Path->JRE System Library(select)-> Edit.
右键单击您的项目-> 属性-> Java 构建路径-> JRE 系统库(选择)-> 编辑。
STEP 2:"JRE System Library"(Window):
第 2 步:“JRE 系统库”(窗口):
Alternate JRE(Select and choose the JRE)-> Installed JREs(Click).
备用 JRE(选择并选择 JRE)-> 已安装的 JRE(单击)。
STEP 3: "Preferences(Filtered)"(Window)
第 3 步:“首选项(已过滤)”(窗口)
Select the JRE under 'Installed JRE's' -> Edit(Click)
选择“已安装 JRE”下的 JRE -> 编辑(单击)
STEP 4: "Edit JRE"(Window)
第 4 步:“编辑 JRE”(窗口)
Click on 'Add External JARs'
单击“添加外部 JAR”
STEP 5: "JAR Selection"(Window)
第 5 步:“JAR 选择”(窗口)
Select the 'tools.jar' (under JDK->lib) --> 'Open' ->'Finish'-->'OK'-->'Finish' --> 'OK'.
选择'tools.jar'(在JDK->lib 下)--> 'Open' ->'Finish'-->'OK'-->'Finish' --> 'OK'。
We are good to go!!! Hope this helps..
我们可以出发了!!!希望这可以帮助..