eTechtips

Tech Tips and Insights

Tag: ant

  • Ant unable to find tools.jar

    When attempting to run ant I get the following message: “Unable to locate tools.jar. Expected to find it in C:Program Files (x86)Javajre6libtools.jar”

    This had to do with my JAVA_HOME not pointing to a Java JDK.

    So if you download a JDK and update your JAVA_HOME environment variable to point to that directory, ant should run happily.

    In BASH:
    export JAVA_HOME=/path/to/jdk

    IN DOS:
    set JAVA_HOME=c:PATHtojdk

    0 Comments
  • Sample Ant file

    Every once in awhile I go back and try to figure out how to create a basic ant build.xml file. So I am just placing a sample build.xml here.

    The directory structure should be something like
    ./build.xml
    ./src/HelloWorld.java

    The targets will create the build directory and compile the source and run a test execution of the class.

    <project name="HelloWorld" basedir="." default="main">
    <target name="clean">
    <delete dir="build"/>
    </target>
    
    <target name="compile">
    <mkdir dir="build/classes"/>
    <javac srcdir="src" destdir="build/classes"/>
    </target>
    
    <target name="jar" depends="compile">
    <mkdir dir="build/jar"/>
    <jar destfile="build/jar/HelloWorld.jar" basedir="build/classes">
    <manifest>
    <attribute name="Main-Class" value="HelloWorld"/>
    </manifest>
    </jar>
    </target>
    
    <target name="run" depends="jar">
    <java jar="build/jar/HelloWorld.jar" fork="true" />
    </target>
    
    <target name="main" depends="clean,run"/>
    
    </project>
    
    0 Comments