ant error JAVA_HOME does not point to SDK

陌路散爱 提交于 2020-01-11 07:26:10

问题


I am trying to install SOLR and running "ant example" The build gets pretty far but then gives an error:

/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"

I have explicity set JAVA_HOME (see below)

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

However the JAVA_HOME when I run ant is showing as /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre instead of # echo $JAVA_HOME /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/ . I cannot figure out where this is being set. I also set ANT_HOME as it was stated in some other posts that this might fix the issue.

# echo $ANT_HOME
/usr/share/ant/

That does not fix it either.


回答1:


OK, I was able to solve the problem I was having. I had set JAVA_HOME, but not as a system environment variable.

Basically, ant was spawning a new process and wasn't picking up any of the shell variables I had set. So while my current shell could see $JAVA_HOME, when ant was running it could not. It was Brian Kelly's helpful comment on the question of:

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

This showed the location ant was looking for java by default, and proved that my variable wasn't being picked up.

The machine I was connected to was running bash, so I had to put the lines below into .bash_profile:

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

After this, it ran without a hitch.

Hope this helps someone.



来源:https://stackoverflow.com/questions/6285301/ant-error-java-home-does-not-point-to-sdk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!