Ant NEWBIE: Can Ant save (open) source automatically before build?

Posted on 2006-03-20
Last Modified: 2010-03-31
Dear Ant Experts,

In Eclipse, I have a build.xml.  Each time I run it, I'm prompted to save the (Java) source I'm currently editing.  (I always want to save it.)  I have not been able to get Eclipse to save it automatically.  Can I add something to my build.xml that will save all changed files in my ...src directory before building (even if I currently have them open in Eclipse?)

Here is my build.xml:

<?xml version="1.0"?>
<project name="project" default="copy">
      <property name="outputDir" value="C:\FTG\Projects\Total\classes" />
      <property name="sourceDir" value="C:\FTG\Projects\Total\src" />
      <property name="libsDir" value="C:\FTG\Projects\Total_Libraries" />
     <target name="build">
          <path id="mypath">
               <fileset dir="C:\FTG\Projects\Total_Libraries" id="id">
                    <include name="**/*.jar" />
          <javac srcdir="${sourceDir}" destdir="classes" classpathref="mypath" includes="*.java">
    <target name="copy" depends="build" >
          <copy todir="\\Ftgds\Program Files\MyCompany\Total\j2re1.4.1_03\bin">
        <fileset dir=".\classes"/>
      <copy todir="C:\Program Files\MyCompany\Total\j2re1.4.1_03\bin">
    <fileset dir=".\classes"/>

Question by:BrianMc1958
    LVL 92

    Expert Comment

    no :)

    are you running build from eclipse or command line

    Author Comment

    I'm running from Eclipse.  

    Specifically, I hit the "Run MyProject build.xml" button (green arrow with little red thing), which then does run my build.xml.

    I posted this because a previous post failed (at least for me) to get Eclipse to save automatically.  (Someone told me an obvious solution: Preferences > WorkSpace > Save automatically.  Duh. But for some reason, it doesn't work for me).  

    Is there a work-around?

    LVL 10

    Accepted Solution

    Hi BrianMc1958,

    There is a preference in eclipse which you can set for that.
    It will automatically save all dirty editors (unsaved editors) before running.

    Go to Window -> Preferences -> Run/Debug -> Launching

    There, you can see a radio button "Save dirty editors before launching"
    Set that option to always and it will never again ask you for saving!!

    LVL 86

    Expert Comment

    Just open up the command prompt, and, making sure the classpath and libraries are set in accordance with Eclipse, run it from the command line

    Author Comment

    Dear radarsh:

    Thanks! It works!  I'm HAPPY NOW!

    LVL 10

    Expert Comment


    I have posted a comment at one of your previous questions regarding same topic.
    Please check that too.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Title # Comments Views Activity
    seriesUp challenge 7 79
    Is there any core JDK API for PDF Creation? 5 31
    sumHeights  challenge 17 50
    word0 challenge 3 26
    For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
    Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
    Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
    Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now