0
votes

I am working on a simple java editor that uses ant to call JDK.

On eclipse everything work fine, I am able to build build.xml. The problems is when I export my Editor to an executable jar, and I try to build the build.xml of a project, I get the famous problems:

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 "C:\Program Files (x86)\Java\jre7"

Important:

If i run my jar Editor from cmd it's work fine ,but if i double click the Editor jar it doesn't work , i get the famous problem (unable to find javac compiler...).

Notice:

  1. JAVA_HOME points to the JDK.

  2. I am using ant.jar and ant-launcher.jar.

  3. Eclipse points to my JDK installation.

  4. tools.jar is added to JDK/lib folder

3
"Perhaps JAVA_HOME does not point to the JDK." - It looks like your JAVA_HOME points to a JRE installation instead of a JDK. The JRE does not come with javac and other development tools. Change your JAVA_HOME environment variable, restart eclipse, and you should be good. - JimmyB
An "executable JAR" is a JAR file that includes your classes, the necessary JDK classes, and the JVM. It does not include the Java compiler. - Hot Licks

3 Answers

2
votes

the solution is to set fork attribute to yes on javac target .

1
votes

Perhaps JAVA_HOME does not point to the JDK.

JAVA_HOME is currently set to C:\Program Files (x86)\Java\ jre7

The message is fairly informative and to the point, is it not?

1
votes

Your JAVA_HOME looks like it is pointing to a JRE installation, not a JDK installation. (The error message says it is "C:\Program Files (x86)\Java\jre7"!)

A JRE does not include any of the Java development tools ... such as the javac Java compiler that Ant is trying to load / use.

If you really have a JDK installation on your machine, then all you need to do is to change the JAVA_HOME environment variable so that it refers to it ... instead of the JRE. Otherwise, you also need to download and install the relevant JRE.