JAVA_HOME does not point to the JDK

2019-03-17 13:29发布

I am trying to follow a tutorial about how to use ant to build and run your application. I've followed all the steps and have created the build file, but when I try to run ant it gives me this error.

BUILD FAILED /home/bilal/tmp/ant/build.xml:19: 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-6-openjdk/jre"

Any ideas how to resolve this issue ?

16条回答
Viruses.
2楼-- · 2019-03-17 14:21

Under Jenkins it complains like :

/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64/ doesn’t look like a JDK directory

Reason : Unable to found any Dev Kit for JDK.

Solution:

Please make sure to install openjdk-devel package as well along with your JDK-1.8* version and reexport with : # source ~/.bash_profile

查看更多
爷、活的狠高调
3楼-- · 2019-03-17 14:22

The JAVA_HOME you have above only points to the JRE, which does not contain the compiler. Set your JAVA_HOME to

/usr/lib/jvm/java-6-openjdk

...and try again.

查看更多
Rolldiameter
4楼-- · 2019-03-17 14:29

Once you update the JAVA_HOME path as stated in the answer, you should do this:

$source ~/.bashrc

This will refresh bashrc show the updated path in $JAVA_HOME when you check again.

查看更多
5楼-- · 2019-03-17 14:30

I had a similar problem and it turned out the issue was having both versions 6 & 7 of OpenJDK. The answer comes from r-senior on ubuntu forums (http://ubuntuforums.org/showthread.php?t=1977619) --- just uninstall version 6:

sudo apt-get remove openjdk-6-*

make sure that JAVA_HOME and CLASSPATH aren't set to anything since that isn't actually the problem.

查看更多
对你真心纯属浪费
6楼-- · 2019-03-17 14:30

Execute:

$ export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.141-3.b16.el6_9.x86_64

and set operating system environment:

vi /etc/environment

Then follow these steps:

  1. Press i
  2. Paste

    JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.141-3.b16.el6_9.x86_64
    
  3. Press esc

  4. Press :wq
查看更多
再贱就再见
7楼-- · 2019-03-17 14:34

Make JAVA_HOME variable point to a jdk installation, not jre.

You are referencing the runtime environment, not the development kit - it can't find the compiler because its not there.

From the line you posted, which states you have open-jdk you can just remove the jre at end:

export JAVA_HOME='/usr/lib/jvm/java-6-openjdk/'
查看更多
登录 后发表回答