Wednesday, July 09, 2014


If you face this problem, probably you are using Ant tasks that include the javac task for compiling Java source. This simply means that Ant could not find a Java compiler.

BUILD FAILED
D:\research\ant\firstbuild\build.xml:9: 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\Java\jre7"

Total time: 0 seconds

For Eclipse user you can add items to Ant’s class-path from the Ant > Runtime preference page. If you launch Eclipse by using a full JDK instead of a JRE, tools.jar should appear on the Ant class-path automatically.



Ant also allowing you to plug in your own Java compiler, such as the Java compiler that is built into Eclipse. So alternatively, you can simply add the following line to your build file to specify the compiler:

<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter">
</property>

If you executed the command from command line, make sure JAVA_HOME variable is set to JDK, instead of JRE in classpath variable. You can use following command to set JAVA_HOME varriable.

For Windows user:

set JAVA_HOME=C:\Program Files\Java\jdk1.7.0_55

For Linux User:

export JAVA_HOME=/opt/java/jdk1.7.0_55

Apart from this you can explicitly mention ant to execute particular executable using following excerpt of code.

<?xml version="1.0"?>
<project name="firstbuild" default="compile">
    <target name="compile">
        <javac     srcdir="."
                destdir="."
                fork="yes"
                executable="C:\Program Files\Java\jdk1.7.0_55\bin\javac"
                compiler="javac1.7"
        />
        <echo>compilation complete!</echo>
    </target>
</project>

I hope this should solve the problem. Please drop by if you have any query and feel free to make any suggestion.

11 comments:

  1. Useful post with good explanation and thanks for taking time to share his post.
    Digital Marketing Training in Chennai | SEO Training in Chennai

    ReplyDelete
  2. Useful post with good explanation and thanks for taking time to share his post.
    java training in chennai

    ReplyDelete
  3. Excellent post on Java.I got some useful tips from your webpage.Keep sharing more.
    Thanks,
    Java Courses in Chennai | J2EE Training in Chennai | JAVA Training Chennai

    ReplyDelete
  4. This data is great and amazing. A debt of gratitude is in order for taking an ideal opportunity to talk about this, I feel upbeat about it and I adore adapting more about this theme. I utilize your manual for teach my understudies.
    Regards,
    Hibernate Training in Chennai | Hibernate course in Chennai | Spring and Hibernate Training in Chennai

    ReplyDelete
  5. Useful post.Mobile application testing is a procedure by which application programming produced for handheld cell phones is tested for its consistency, functionality and usability.
    Thanks,
    Mobile Testing Training in Chennai | Mobile Testing Training | Mobile Apps Testing

    ReplyDelete
  6. Im no expert, but I believe you just made an excellent You certainly understand what youre speaking about, and I can truly get behind that.
    Best JAVA Training institute in Chennai|Java Courses in Chennai

    ReplyDelete

Categories

.
Powered by Blogger.

Popular Posts

Like Us