[英]Why maven ignores my JAVA_HOME?
This is what I'm getting when mvn
is executed from CruiseControl:这是从 CruiseControl 执行mvn
时得到的结果:
Unable to locate the Javac Compiler in: /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/../lib/tools.jar Please ensure you are using JDK 1.4 or above and not a JRE (the com.sun.tools.javac.Main class is required). In most cases you can change the location of your Java installation by setting the JAVA_HOME environment variable.
At the same time, starting it from command line gives correct result.同时,从命令行启动它会给出正确的结果。 Why mvn
is going into this tools.jar
?为什么mvn
要进入这个tools.jar
? Why it is ignoring my JAVA_HOME
?为什么它忽略我的JAVA_HOME
? And how can I fix it?我该如何解决?
I don't know what are the values of JAVA_HOME/PATH
when mvn
is started from CC.我不知道从 CC 启动mvn
时JAVA_HOME/PATH
的值是什么。 I would really love to get this information but I don't know how.我真的很想得到这些信息,但我不知道如何。 CC itself is started from user cc
and env
for this user gives me (it's CentOS 5.4): CC 本身是从用户cc
启动的,这个用户的env
给了我(它是 CentOS 5.4):
JAVA_HOME=/usr/java/default
PATH=/usr/local/maven/bin:/usr/local/bin:/bin:/usr/bin:/home/cc/bin
我遇到了同样的问题,简单地重新安装 Java JDK 为我解决了这个问题:
apt-get install openjdk-6-jdk
Why mvn is going into this tools.jar?为什么 mvn 要进入这个 tools.jar?
Because tools.jar
contains the com.sun.tools.javac.Main
class which is used to invoke the javac
compiler programmatically.因为tools.jar
包含用于以编程方式调用javac
编译器的com.sun.tools.javac.Main
类。
Why it is ignoring my JAVA_HOME为什么它忽略了我的 JAVA_HOME
That's the "interesting" part (since it's working outside CC).这是“有趣”的部分(因为它在 CC 之外工作)。 Are you running CC with a dedicated user?您是否与专门的用户一起运行 CC? If yes, is JAVA_HOME
well defined for this user?如果是,是否为该用户定义了JAVA_HOME
? What is the output of什么是输出
echo $JAVA_HOME -or-
echo $PATH
Assuming that you have a linux machine.假设你有一台 linux 机器。
/usr/bin/java
, this is a symbolic link.看看/usr/bin/java
,这是一个符号链接。 Look where is a target of this symbolic link (in my case the target is at this location /etc/alternatives/java
)看看这个符号链接的目标在哪里(在我的例子中,目标在这个位置/etc/alternatives/java
)/etc/alternatives/java
is symbolic link too. /etc/alternatives/java
也是符号链接。 Create new symbolic link to "proper" JVM (eg Sun's JVM)创建指向“正确”JVM(例如 Sun 的 JVM)的新符号链接/etc/alternatives/java
with newly created symbolic link.用新创建的符号链接替换/etc/alternatives/java
。This works for Ubuntu distribution.这适用于 Ubuntu 发行版。 There is an automatic way how to do that but I forgot it actually :D有一种自动方法可以做到这一点,但我实际上忘记了:D
mvn
runs everything in a command environment that does not inherit the local environment variables of your current shell. mvn
在不继承当前 shell 的本地环境变量的命令环境中运行所有内容。
export JAVA_HOME
first then your commands may work.首先,您的命令可能会起作用。
I ended up having to point to the Oracle Java 7 installations on Ubuntu.我最终不得不指向 Ubuntu 上的 Oracle Java 7 安装。 Gradle (1.6) does not seem to like sym links at all. Gradle (1.6) 似乎根本不喜欢符号链接。 So I edited the /opt/gradle/gradle-1.6/bin/gradle file to export a JAVA_HOME of /usr/lib/jvm/java-7-oracle at the top of the script.因此,我编辑了 /opt/gradle/gradle-1.6/bin/gradle 文件以在脚本顶部导出 /usr/lib/jvm/java-7-oracle 的 JAVA_HOME。 It's happy now.现在很幸福。
I know this is far outdated question, but I ended up there googling the same problem.我知道这是一个过时的问题,但我最终在谷歌上搜索了同样的问题。 So this solution also works fine: just put "fork='yes'" in "javac" task.所以这个解决方案也很好用:只需将“fork='yes'”放在“javac”任务中。 After this javac task become honoring the JAVA_HOME setting.在此 javac 任务成为尊重 JAVA_HOME 设置之后。
在 Sun 版本中键入以下行
sudo update-java-alternatives -s java-6-sun
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.