Want an eclipse java project to run ant build files automatically

51,481

Solution 1

Step 1: Add the build file to your ant view

Click the add button and select the build.xml file from the project. You can also drag the build.xml file onto the ant view (To add the ant view to your perpective, go to Window > Show View > Other…)

Step 2: Run as Ant Build

In your ant view, right click the newly added build file and select Run As > Ant Build… In the dialog window, select the ‘Hide internal targets not selected for execution’ option in the Targets tab. You can rename the builder in the box at the top of the window if you wish (I usually remove the trailing ‘build.xml’. Click Apply and Close.

Step 3: Setup automatic build

Right click on the project, select Properties, then Builders. Click Import. Before closing the screen, highlight the imported build and select edit. Go to the Targets tab select clean for ‘After a clean’ and deploy.local for ‘Auto build’. Apply the changes and close.

Step 4: Enable Auto Build

Go to Project > Build Automatically

source: http://www.simonwhatley.co.uk/using-ant-with-eclipse

Solution 2

Go to your project properties, select "Builders", and add a new Ant Builder. You may specify which targets to run at what time (during a clean, after a clean, etc.), and which resources (if any) to refresh in Eclipse after your ant target is executed.

Solution 3

Project/Builders/New/Ant Builder

There you can add your custom ant build.

Solution 4

At least with Eclipse 4.2 (Juno), the ability to auto-build with Ant has been removed. Under the builder configuration -> "Auto Build", there is a message: "". That said you, can still work around this by:

  • Follow the steps above for creating your Ant builder. This will create a file in projectDirectory/.externalToolBuilders.
  • Modify projectDirectory/.externalToolBuilders/YourLaunchName.launch:
    • You'll need to add auto, to this line: <stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,auto,"/>
    • Specify the target you want run for auto by adding: <stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AUTO_TARGETS" value="compile-jar,"/>

You can look at your Ant builder configuration and see that everything looks good: enter image description here

Share:
51,481
Fredrik
Author by

Fredrik

Consultant and Software programmer by day. Superhero by night. Speaks fluently Java. Works agile and test driven, or at least feels appropriately ashamed when failing to do so. Works as a consultant with all things Java.

Updated on July 09, 2022

Comments

  • Fredrik
    Fredrik almost 2 years

    I have an Eclipse Java project, not a plugin project. And the project has some external dependencies that I handle in two separate ant files. Everything works fine, but I want to force Eclipse to run the ant files everytime it builds my project.

    How can I do that?

    If this had been a plugin project I would have handled it in a customBuildCallbacks.xml and included it in my build.properties, but doesnt seem to work when its just a java project

  • boztalay
    boztalay almost 11 years
    If anyone is lost on the last step about setting up the Targets tab, when you click "Set Targets...", uncheck "Hide internal targets not selected for execution". I got it to work with this, otherwise nothing was coming up in that dialog.
  • vintprox
    vintprox about 4 years
    That's actually helpful, thanks! Didn't know about "Ant" view's existence in Eclipse