Java Preprocessor Using Eclipse Part 6 PDF Print E-mail
Written by Administrator   
Sunday, 03 January 2010 20:14

Java Preprocessor Using Eclipse Part 6


 <-- Prev Page    Next Page -->

 Now the project should build by running the Ant script.    Now it is time to tell Eclipse to use this Ant script (instead of it's own method) to build the project by default.  Right-click on the Hello project and select 'Properties' which is probably all the way on the bottom.   On the left, choose 'Builders'.


Project Properties Builders

Uncheck 'Java Builder' and check our new prebopBuild.xml script.   Now by default, our script will be compiling the project.


  If the script doesn't work and you see an error message about the JAVA_HOME not being set, then you need to set the environment variable to JAVA_HOME up on your computer.   On my system JAVA_HOME has the value shown highlighted in blue below:


JAVA_HOME env variable


Assuming that building works, it is now time to add a step for cleaning the build.   Edit the prebopBuild.xml file so it has the extra section for the 'clean' target:


<?xml version="1.0"?>
<project name="Hello" default="compile" basedir=".">
    <!-- Sets variables which can later be used. -->
    <!-- The value of a property is accessed via ${} -->
    <property name="src" location="src" />
    <property name="build" location="bin" />

    <!-- Creates the  build, docs and dist directory-->
    <target name="clean">
        <delete dir="${build}" />

    <!-- Creates the  build, docs and dist directory-->
    <target name="makedir">
        <mkdir dir="${build}" />

    <!-- Compiles the java code -->
    <target name="compile" depends="makedir">
        <javac srcdir="${src}" destdir="${build}" />


What we have done is to add a new capability of what the build file can do.   It can now clean as well as build.   But now the settings for the build must be updated.


Adding the 'clean' target to the settings

 Note the order must be clean, then compile.  Otherwise your executables will be deleted right after they are created.

 And now, apply these changes, then go to the Project Properties, and back to the Builders page.   Then click on the prebopBuild.xml file, then the 'Edit' button.   This will bring up a dialog which looks identical to the External Tools Configuration dialog, but it is a little different.


Edit launch add clean target

If your 'Targets' tab does not look this screen, make sure you are actually looking at the Edit Launch Configuration Properties and not the 'Edit Configuration and Launch'.   I do not quite understand the difference, but you bring the dialogs up differently.

   The line 'During a Clean' which is in read is asking you to specify which target to use for a generic Clean operation.   We want the one called 'clean'.

   Once the target has been set for the 'Clean' operation, the project will once again show up in the list when you go to clean projects.


 <-- Prev Page    Next Page -->








Last Updated on Monday, 04 January 2010 03:46

Sponsored Links

Bold Inventions, Powered by Joomla!; Joomla templates by SG web hosting