Maven 没有正确选择 JAVA_HOME [英] Maven not picking JAVA_HOME correctly

查看:49
本文介绍了Maven 没有正确选择 JAVA_HOME的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 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 FilesJavajre6lib	ools.jar -> [Help 1]

问题在于 tools.jar 位于C:Program FilesJavajdk1.6.0_26lib"中并且在 C:Program FilesJavajdk1.6.0_26lib 中正确设置code>JAVA_HOME 环境变量,但 Maven 仍在 jre 文件夹中查找错误消息C:Program FilesJavajre6lib ools.jar".

The issue is that the tools.jar is in "C:Program FilesJavajdk1.6.0_26lib" 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 FilesJavajre6lib ools.jar".

C:>echo %JAVA_HOME%
C:Program FilesJavajdk1.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 FilesJavajdk1.6.0_26lib	ools.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(before -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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆