Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6057921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:32:29+00:00 2026-05-23T08:32:29+00:00

I have an Ant script that I would like to execute using a button

  • 0

I have an Ant script that I would like to execute using a button that I made. The problem now is that I would get an error saying:

BUILD FAILED

X:\eclipseMT\runtime-workspace\testTest\diagram1_Sc2_TestScript.xml:68:
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\jdk1.6.0_12\jre”

I’m pretty sure that my classpath is correct and I can execute the same script using Eclipse internal Ant executor.

This is my ant script:

<property name="src.dir" value="src" />
<property name="test.dir" value="test" />
<property name="test.wstest.dir" value="${test.dir}/wstest" />
<property name="junit.dir" location="X:\eclipseMT\plugins\org.junit_3.8.2.v3_8_2_v20100427-1100"/>
<property name="build.dir" value="build" />
<property name="build.classes.dir" value="${build.dir}/classes" />
<property name="build.test.dir" value="${build.dir}/test"/>
<property name="build.test.classes.dir" value="${build.test.dir}/classes" />
<property name="build.test.data.dir" value="${build.test.dir}/data" />
<property name="build.test.reports.dir" value="${build.test.dir}/reports" />
<property name="dist.dir" value="dist" />
<property name="lib.dir" value="lib" />
<property name="build.debug" value="true" />

<path id="compile.classpath">
    <fileset dir="lib">
        <include name="*.jar"/>
    </fileset>
</path>

<path id="test.compile.classpath">
    <path refid="compile.classpath" />
    <pathelement location="${build.classes.dir}"/>
</path>

<path id="test.classpath">
    <path refid="test.compile.classpath" />
    <pathelement location="${build.test.classes.dir}"/>
</path>

<target name="init" description="create dir desc">
    <mkdir dir="${build.dir}" />
    <mkdir dir="${build.classes.dir}" />
    <mkdir dir="${dist.dir}" />
    <mkdir dir="${lib.dir}" />
    <copy todir="${lib.dir}">
        <fileset dir="${junit.dir}"/>
    </copy>
    <echo>make init dir done</echo>
</target>

<target name="test-init" depends="init" description="create test dir">
    <mkdir dir="${build.test.dir}" />
    <mkdir dir="${build.test.classes.dir}" />
    <mkdir dir="${build.test.data.dir}"/>
    <mkdir dir="${build.test.reports.dir}"/>
<echo>make test init dir done</echo>
</target>

<target name="clean" depends="init, test-init" description="remove previous build">
    <delete verbose="true">
        <fileset dir="${build.classes.dir}" />
        <fileset dir="${build.test.classes.dir}" />
        <fileset dir="${build.test.data.dir}" />
        <fileset dir="${build.test.reports.dir}" />
        <fileset dir="${dist.dir}" />
    </delete>
    <echo>clean build dir done</echo>
</target>

<target name="compile" depends="clean" description="compile java source">
    <javac srcdir="${src.dir}" destdir="${build.classes.dir}" classpath="${build.classes.dir}" debug="on" fork="no" includeAntRuntime="false" />
    <echo>compile source done</echo>
</target>

<target name="test-compile" depends="compile, test-init" description="compile test source">
    <javac srcdir="${test.wstest.dir}" destdir="${build.test.classes.dir}" debug="true" includeAntRuntime="true">
        <classpath refid="test.compile.classpath" />
    </javac>
    <echo>compile test src done</echo>
</target>

<target name="test-reporting" depends="test-compile" description="report even if fail">
    <junit printsummary="false" errorproperty="test.failed" failureproperty="test.failed">
        <classpath>
            <path refid="test.classpath" />
        </classpath>
        <formatter type="brief" usefile="false" /> 
        <formatter type="xml" />
        <batchtest todir="${build.test.data.dir}" unless="testcase">
            <fileset dir="${build.test.classes.dir}" />
            <!--fileset dir="${build.test.classes.dir}" includes="Sc2TestClient*.class" /-->
        </batchtest>
    </junit>

    <junitreport todir="${build.test.data.dir}">
        <fileset dir="${build.test.data.dir}">
            <include name="WSTEST-*.xml" />
        </fileset>
        <report format="frames" todir="${build.test.reports.dir}" />
    </junitreport>
    <fail if="test.failed">
        Test failed. Check ${build.test.reports.dir}
    </fail>
</target>

<target name="default" depends="test-reporting" description="test the whole suite">
    <echo>all test done</echo>
    <tstamp>
        <format property="buildTime" pattern="yyyy-MM-dd' 'HH:mm:ss" />
    </tstamp>
    <echo>build time = ${buildTime}</echo>
</target>

This is my button code:

Project p = new Project();

    try {
        p.setUserProperty("ant.file", buildFile.getAbsolutePath());     

        DefaultLogger consoleLogger = new DefaultLogger();
        consoleLogger.setErrorPrintStream(System.err);
        consoleLogger.setOutputPrintStream(System.out);
        consoleLogger.setMessageOutputLevel(Project.MSG_INFO);

        p.addBuildListener(consoleLogger);          
        p.fireBuildStarted();
        p.init();

        ProjectHelper helper = ProjectHelper.getProjectHelper();
        p.addReference("ant.projectHelper", helper);
        helper.parse(p, buildFile);
        p.executeTarget(p.getDefaultTarget());
        p.fireBuildFinished(null);
    } catch (Throwable t) {
        t.printStackTrace();
        p.fireBuildFinished(t);
        return false;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:32:30+00:00Added an answer on May 23, 2026 at 8:32 am

    A friend give me a reference to this earlier question: Setting JAVA_HOME when running Ant from Java

    The problem basicly is with ant because it has point java.home to ‘jre’ instead of ‘jdk’. It got overwritten everytime ant was call to execute.

    The solution is to add:

    fork="yes"

    to each compilation script and add:

    p.setProperty("java.home", "C:\\Program Files\\Java\\jdk1.6.0_26");

    to the java execution code.

    Hope this help others 😀

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Ant script that performs a copy operation using the 'copy' task
I have an ant script that does a headless build using the following ant
I have an Ant project that uses a bit of Coffee Script. I would
I have the problem that an specific step in Ant can only be executed
I would like to clarify the if and unless statements in ANT script I
I have a list of Eclipse projects that I would like to compile based
I have the following ant script that I can't seem to find a way
I have an Ant build that will sometimes execute a 'git push' within a
We have inherited an ant build file but now need to deploy to both
I am using apache ant to generate javadoc for my project. I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.