我正在尝试安装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/
这也无法解决。
答案 0 :(得分:3)
好的,我能够解决我遇到的问题。我设置了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
在此之后,它顺利运行。
希望这有助于某人。