Search code examples
javawindowsantbuildibatis

Why can't Ant find javac?


There is the following build.bat file:

echo off  
set JAVA_HOME="C:\Program Files\Java\jdk1.6.0_25"  
set BUILD_CP="C:\Program Files\Java\jdk1.6.0_25\bin\lib\tools.jar";"C:\Program Files\Java\jdk1.6.0_25\bin";..\devlib\ant.jar;..\devlib\optional.jar;..\devlib\junit.jar;..\devlib\xercesImpl.jar;..\devlib\xmlParserAPIs.jar;  
"C:\Program Files\Java\jdk1.6.0_25\bin\java" -classpath %BUILD_CP% org.apache.tools.ant.Main -buildfile build.xml all  

set BUILD_CP=  

pause  

When I run it I get:

BUILD FAILED

file:D:/Development/Java/Frameworks/JMeter/TestDemoIbatis/iBATIS_JPetStore-4.0.5/build/build.xml:29: 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

Total time: 0 seconds
Press any key to continue . . .  

But my JAVA_HOME, PATH is properly set:

enter image description here

Update:
The ant script:

<project name="JPetStore" default="all" basedir=".">  

  <property file="build.properties"/>  

  <path id="classpath">  
    <pathelement location="${src}/"/>  
    <fileset dir="${lib}" includes="**/*.jar" />  
    <fileset dir="${devlib}" includes="**/*.jar" />  
  </path>  

  <target name="clean" >  
    <delete dir="${wars}"/>  
    <delete dir="${webapp}"/>  
    <delete>  
      <fileset dir="${src}" >  
        <include name="**/*.class"/>  
      </fileset>  
    </delete>  
  </target>  

  <target name="prepare" depends="clean">  
    <mkdir dir="${wars}"/>  
    <mkdir dir="${webapp}"/>  
    <mkdir dir="${webapp}/WEB-INF/classes"/>  
    <mkdir dir="${webapp}/WEB-INF/lib"/>  
  </target>  

  <target name="compile" depends="prepare"> //LINE 29 that fails 
    <javac srcdir="${src}" destdir="${webapp}/WEB-INF/classes" deprecation="off" debug="${debug}">  
      <classpath refid="classpath"/>  
    </javac>  
  </target>  

  <target name="assemble.view">  
    <copy todir="${webapp}">  
      <fileset dir="${web}">  
        <include name="**/*.jsp"/>  
        <include name="**/*.html"/>  
      </fileset>  

    </copy>  
  </target>  

  <target name="assemble" depends="compile">  
    <copy todir="${webapp}/WEB-INF/classes">  
      <fileset dir="${src}" >  
        <exclude name="**/*.java"/>  
        <exclude name="**/*.class"/>  
      </fileset>  
    </copy>  
    <copy todir="${webapp}/WEB-INF/lib">  
      <fileset dir="${lib}" />  
    </copy>  
    <copy todir="${webapp}">  
      <fileset dir="${web}" />  
    </copy>  
  </target>  

  <target name="war" depends="assemble">  
    <jar jarfile="${wars}/jpetstore.war">  
      <fileset dir="${webapp}">  
        <include name="**/*"/>  
      </fileset>  
    </jar>  
  </target>  

  <target name="all" depends="war" />  

</project>  

What is the problem here? I am in Windows7/64-bit


Solution

  • This just worked for me:

    echo off
    
    set JAVA_HOME="c:\Program Files\Java\jdk1.6.0_25"
    
    set BUILD_CP=%JAVA_HOME%\lib\tools.jar;..\devlib\ant.jar;..\devlib\optional.jar;..\devlib\junit.jar;..\devlib\xercesImpl.jar;..\devlib\xmlParserAPIs.jar;
    
    %JAVA_HOME%\bin\java -classpath %BUILD_CP% org.apache.tools.ant.Main -buildfile build.xml all
    
    set BUILD_CP=
    
    pause
    

    Note that I had to change the build.xml to add the source=1.4 directive:

    <javac srcdir="${src}" destdir="${webapp}/WEB-INF/classes" deprecation="off" debug="${debug}" source="1.4">