Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java ant Eclipse run error [duplicate]

Tags:

java

ant

Possible Duplicate:
ant error JAVA_HOME does not point to SDK

I'm getting the following error:

BUILD FAILED
C:\Users\myname\Documents\CMSC\Proj1\build.xml:22: 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"

Total time: 1 second

My build.xml file contains the following code:

<project name="Project1" default="compile" basedir=".">

  <description>
    Build file for Project1
  </description>

  <!-- global properties for this build file -->
  <property name="source.dir" location="src"/>
  <property name="build.dir" location="bin"/>
  <property name="doc.dir" location="doc"/>
  <property name="main.class" value="proj1.Project1"/>

  <!-- set up some directories used by this project -->
  <target name="init" description="setup project directories">
    <mkdir dir="${build.dir}"/>
    <mkdir dir="${doc.dir}"/>
  </target>

  <!-- Compile the java code in ${src.dir} into ${build.dir} -->
  <target name="compile" depends="init" description="compile java sources">
    <javac srcdir="${source.dir}" destdir="${build.dir}"/>
  </target>

  <!-- execute the program with the fully qualified name in ${build.dir} -->
  <target name="run" description="run the project">
    <java dir="${build.dir}" classname="${main.class}" fork="yes">
        <arg line="${args}"/>
    </java>
  </target>

  <!-- Delete the build & doc directories and Emacs backup (*~) files -->
  <target name="clean" description="tidy up the workspace">
    <delete dir="${build.dir}"/>
    <delete dir="${doc.dir}"/>
    <delete>
      <fileset defaultexcludes="no" dir="${source.dir}" includes="**/*~"/>
    </delete>
  </target>

  <!-- Generate javadocs for current project into ${doc.dir} -->
  <target name="doc" depends="init" description="generate documentation">
    <javadoc sourcepath="${source.dir}" destdir="${doc.dir}"/>
  </target>

</project>

What am I doing wrong here? It appears that it's trying to find a javac file in my src folder but I don't know how to fix that.

like image 980
Haque1 Avatar asked Mar 03 '26 18:03

Haque1


2 Answers

The JAVA_HOME must be pointed to JDK and not JRE.

To test it, before executing ant type set JAVA_HOME=C:\Program Files (x86)\Java\jdk1.7.0_07 or whatever version you have.

like image 158
Jagger Avatar answered Mar 06 '26 07:03

Jagger


Download the latest JDK here. Install it and notice where it goes. For example, the 32-bit JDK should install to C:\Program Files (x86)\Java\jdkSOMETHING.

In Eclipse, go to Window > Preferences > Java > Installed JREs and click Add > Standard JVM (then Next). Browse to the directory noted above for the JDK and then hit Finish. To check that your project is using this JDK, right-click the project and go to Properties. From there, look for Java Build Path. Under the Libraries tab you should see a JRE System Library. If it's not the JDK you just added, click the entry and hit the Edit button and change it.

Now run your Ant build.

like image 44
davidfmatheson Avatar answered Mar 06 '26 08:03

davidfmatheson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!