Maven没有正确选择JAVA_HOME [英] Maven not picking JAVA_HOME correctly
问题描述
我在Windows环境中并使用maven编译我的项目。虽然我刚刚创建了项目并添加了各种库的依赖项。
I am on windows environment and using maven to compile my project. Although I just created the project and added the dependencies for various libararies.
当我添加它们时,maven开始抱怨缺少的 tools.jar
,所以我在下面添加到我的 pom.xml
:
As I added them maven started complaining for the missing tools.jar
, so i added below to my pom.xml
:
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.6</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
当我运行maven安装时,我得到了一个错误的jar错误,如下所示:
When i ran the maven install, i got an error for the missing jar as below :
[ERROR] Failed to execute goal on project GApp: Could not resolve dependencies for project GApp:GApp:war:0.0.1-SNAPSHOT: Could not find artifact com.sun:tools:jar:1.6 at specified path C:\Program Files\Java\jre6\lib\tools.jar -> [Help 1]
问题在于 tools.jar
位于 C:\Program Files \Java \ _jdk1.6.0_26 \ ltl
并在 JAVA_HOME
环境变量但是maven仍在查找jre文件夹,如错误消息 C:\Program Files \ Java @ \\ _jre6 \lib \ tools。 jar
。
The issue is that the tools.jar
is in "C:\Program Files\Java\jdk1.6.0_26\lib
" and is correctly set in the JAVA_HOME
environment variable but the maven is still looking in jre folder as in error message "C:\Program Files\Java\jre6\lib\tools.jar
".
C:\>echo %JAVA_HOME%
C:\Program Files\Java\jdk1.6.0_26
有趣的 :当我设置依赖的完整路径时,它工作得很好。但我不想硬编码。
Interestingly: when i set the full path in dependency, it worked just fine. But i don't want to hard code it.
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.6</version>
<scope>system</scope>
<systemPath>C:\Program Files\Java\jdk1.6.0_26\lib\tools.jar</systemPath>
</dependency>
有人可以建议任何动态解决方案吗?
Can someone suggest any dynamic solution for this?
推荐答案
这是Eclipse Maven支持中的一个错误。根据 Maven规范 ,Eclipse不支持所有全局Maven属性。
It's a bug in the Eclipse Maven support. Eclipse doesn't support all of the global Maven properties as per the Maven specs.
根据规格:
$ {java.home}指定当前JRE_HOME环境的路径
使用相对路径获取例如
${java.home} specifies the path to the current JRE_HOME environment use with relative paths to get for example
至少在Eclipse 4.3.1中是不是这样,这里 java.home
总是指向用于启动Eclipse 的 JRE,而不是构建JRE。
At least in Eclipse 4.3.1 that is not the case, here java.home
always points to the JRE that was used to launch Eclipse, not the build JRE.
要解决此问题,您需要使用JDK中的JRE启动Eclipse,方法是将此类内容添加到 eclipse.ini
(之前 -vmargs
!):
To fix the issue you need to start Eclipse using the JRE from the JDK by adding something like this to eclipse.ini
(before -vmargs
!):
-vm
C:/<your_path_to_jdk170>/jre/bin/server/jvm.dll
这篇关于Maven没有正确选择JAVA_HOME的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!