【问题标题】:ant error JAVA_HOME does not point to SDKant 错误 JAVA_HOME 未指向 SDK
【发布时间】:2011-09-11 05:37:23
【问题描述】:

我正在尝试安装 SOLR 并运行“ant 示例”。构建变得相当远,但随后出现错误:

/root/apache-solr-3.2.0/solr/common-build.xml:250: The following error occurred while executing this line:
/root/apache-solr-3.2.0/lucene/contrib/contrib-build.xml:58: The following error occurred while executing this line:
/root/apache-solr-3.2.0/lucene/common-build.xml:298: The following error occurred while executing this line:
/root/apache-solr-3.2.0/lucene/common-build.xml:733: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre"

我已经明确设置了 JAVA_HOME(见下文)

# echo $JAVA_HOME
/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/

但是当我运行 ant 时 JAVA_HOME 显示为 /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre 而不是 # echo $JAVA_HOME /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/ 。我无法弄清楚这是在哪里设置的。我还设置了 ANT_HOME,正如其他一些帖子中所说的那样,这可能会解决问题。

# echo $ANT_HOME
/usr/share/ant/

这也不能解决问题。

【问题讨论】:

  • 如果你运行 java.home 会显示什么:ant -diagnostics | grep java.home
  • 您应该在您的问题中添加一个 linux 元标记。
  • 我有这个确切的问题。你解决了吗?

标签: ant java-home


【解决方案1】:

好的,我能够解决我遇到的问题。我设置了 JAVA_HOME,但没有设置为系统环境变量。

基本上,ant 正在生成一个新进程,并且没有获取我设置的任何 shell 变量。因此,虽然我当前的 shell 可以看到 $JAVA_HOME,但在 ant 运行时却不能。这是 Brian Kelly 对以下问题的有益评论:

What does java.home show if you run: ant -diagnostics | grep java.home

这表明位置ant默认在寻找java,并证明我的变量没有被拾取。

我连接的机器正在运行 bash,所以我必须将以下行放入 .bash_profile:

JAVA_HOME=/usr/java/jdk1.6.0_18
export JAVA_HOME

此后,它顺利运行。

希望这对某人有所帮助。

【讨论】:

    猜你喜欢
    • 2023-03-15
    • 2014-11-10
    • 2013-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多