Unable to find a javac compiler

喜欢而已 提交于 2019-12-02 15:29:12

All your ant stuff will work fine except the javac task which needs the tools.jar, located in the /lib directory from the JDK, JRE is not sufficient in that case. Therefore the hint from ant : "Unable to find a javac compiler;..."

When working with Eclipse the default setting points to your JRE installation.
So, one of your first steps after starting Eclipse for the first time should be :
Window > Preferences > Java > Installed JREs and change the settings from JRE to JDK.
Alternatively use :
Window > Preferences > Ant > Runtime > Classpath > Global Entries
and add the tools.jar from your JDK/lib folder

I had the same problem. In my case, I fixed it by pointing JAVA_HOME to the JDK folder, rather than the JDK\bin folder.

Currently you have set JAVA_HOME to your installed jre instead of the jdk. Install the current JDK then set JAVA_HOME to your JDK Directory.

You'll find the current jdk here http://www.oracle.com/technetwork/java/javase/downloads/index.html

John

I had this problem and commented on https://stackoverflow.com/a/8406221/866333 saying the fix was no good. (Actually it was reporting that JAVA_HOME was something else so I suggested a script was changing it).

As their reply stated the compiler doesn't lie.

So true, I eventually spotted my old JAVA_HOME variable was something like JDK_v7.0.7 when I'd just removed that (from a 2012 restore DVD) and updated to like JDK_v7.7.1. Why it saw fit to fallback to the JRE, suppose it was a convenience.

eg

JAVA_HOME = c:\Java\JDK_v7.0.7

@runs script...@

Perhaps JAVA_HOME does not point to the JDK. It is currently set to "C:\Program Files\Java\jre7"

@check at cmd prompt@

set
JAVA_HOME = c:\Java\JDK_v7.0.7

so it is kinda lieing isn't it?

I made the mistake of installing the JDK and the JRE to the same location. Installing the JDK automatically installs a JRE and I inadvertently selected the same location as the JDK.

This caused considerable confusion in eclipse.

Install the JDK and the JRE to different locations.

This a is a common mistake by most of the beginners,

JRE is just for running java based code/applications.

If you want to compile java code, you must use JDK.

So open environment variables, and set JAVA_HOME path to JDK folder instead of JRE

I was getting this error while trying to install a java based tool, using ant.

My $JAVA_HOME environment variable, in ~/.bash_profile, was set to /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.141-1.b16.el7_3.x86_64/jre

By removing the jre, (going one directory level up), making $JAVA_HOME, /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.141-1.b16.el7_3.x86_64/, fixed the issue for me.

Don't forget to run, source ~/.bash_profile, after making the change ! HTH

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