Maven 与 Cygwin - 错误:JAVA_HOME 未正确定义
我正在尝试在 cygwin 上运行 Maven。我已将 Maven 添加到路径中,我的 Java 主目录如下所示:
$ echo $JAVA_HOME
/cygdrive/c/Program Files/Java/jdk1.6.0
然而,当我尝试运行 mvn --version
时,我得到以下
Error: JAVA_HOME is not defined correctly.
We cannot execute /cygdrive/c/Program Files/Java/jdk1.7.0_01/bin/java
信息: 知道为什么它不起作用吗? Java版本工作正常,所以这不是java的问题。我也尝试过jdk1.6.0。
运行 which java
给出,
$ which java
/cygdrive/c/windows/system32/java
并且 java -version
给出,
$ java -version
java version "1.7.0_01"
Java(TM) SE Runtime Environment (build 1.7.0_01-b08)
Java HotSpot(TM) Client VM (build 21.1-b02, mixed mode, sharing)
I'm trying to run Maven on cygwin. I've added maven to the path and my Java home looks like this:
$ echo $JAVA_HOME
/cygdrive/c/Program Files/Java/jdk1.6.0
Yet when I try to run mvn --version
, I get this:
Error: JAVA_HOME is not defined correctly.
We cannot execute /cygdrive/c/Program Files/Java/jdk1.7.0_01/bin/java
Any idea why it's not working? Java -version works fine, so it's not a problem with java. I've also tried jdk1.6.0 instead.
Running which java
gives,
$ which java
/cygdrive/c/windows/system32/java
and java -version
gives,
$ java -version
java version "1.7.0_01"
Java(TM) SE Runtime Environment (build 1.7.0_01-b08)
Java HotSpot(TM) Client VM (build 21.1-b02, mixed mode, sharing)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果我运行
mvn.bat
而不是mvn
,则不会出现此问题。因此,由于 Cygwin 将运行 mvn 文件,因此我用批处理文件的软链接 (
ln -s mvn.bat mvn
) 替换了该 mvn 文件。这样,运行mvn
将默默地运行mvn.bat
来优雅地处理这些问题。If I run
mvn.bat
instead ofmvn
, I didn't have this problem.So, since Cygwin will run the mvn file, I replaced this mvn file with a softlink (
ln -s mvn.bat mvn
) to the batch file. This way, runningmvn
will silently run themvn.bat
which handles these problems gracefully.任何使用 Cygwin 和 Maven 的人,这正是您所需要的:
在 Cygwin bash 提示符中:
或:
(您喜欢哪个...)
附加以下内容:
保存并退出。然后运行:
现在您应该能够像在 cmd 提示符下一样使用
mvn
命令。Anyone Using Cygwin and Maven, here's exactly what you need:
In your Cygwin bash prompt:
or:
(Which ever you fancy...)
Append the following:
Save and Exit. Then run:
Now you should be able to use the
mvn
command as you do in cmd prompt.Cygwin 使用 dos 控制台来执行 Maven 构建 (
mvn.bat
)。将 Java 主目录设置为
C:\Program Files\Java\jdk1.7.0_01
位置。Cygwin uses a dos console to execute Maven builds (
mvn.bat
).Set your Java home to the
C:\Program Files\Java\jdk1.7.0_01
location.我在从 cygwin 工具运行 gradle 时遇到了同样的问题。
我曾经将Java主目录设置为包含
bin
文件夹:但后来我意识到,如果包含bin文件夹,有些应用程序无法识别,所以我将类路径更改为
C:\Program Files \Java\jdk1.7.0_67
它开始工作。I was facing the same problem while running gradle from cygwin tool.
I used to set the Java home including the
bin
folder:But later I realized that some application do not recognize if you include bin folder, so I changed the class path to
C:\Program Files\Java\jdk1.7.0_67
and it started working.将
JAVA_HOME
设置为/cygdrive/c/Progra~1/Java/jdk1.6.0
可能会有所帮助。Setting
JAVA_HOME
to/cygdrive/c/Progra~1/Java/jdk1.6.0
might help.