To see how project builders work, we will create a simple project with a single source file and an Ant buildfile that jars up the single class file. Though this example uses Java, it should be noted that project builders are available for all projects, Java or otherwise.
HW
.HelloWorld
with a main method.System.out.println()
statement in the main method, and make
it print a greeting of your choice.projectBuilder.xml
, open the Ant editor on it, enter
the following content, and save changes.
<?xml version="1.0" encoding="UTF-8"?> <project name="HW.makejar" default="makejar" basedir="."> <target name ="makejar" description="Create a jar for the HW project"> <jar jarfile="HelloWorld.jar" includes="*.class" basedir="bin"/> </target> </project>
Makejar
.
In the Main tab, click the Buildfile Browse Workspace...
and set the Location to be the projectBuilder.xml
buildfile created
above. Then click the Base Directory Browse Workspace...
and set the Base Directory to be the HW project.
HelloWorld.jar
is created, we see it in Eclipse. By default, no refreshing is done when a
project builder finishes running, so check Refresh resource upon completion,
then select The project containing the selected resource in the list
of scoped variables. Because refreshing can be expensive, you should, in general,
refresh the smallest entity that contains all resources that will be affected
by your buildfile.
default
target is set to run After a "Clean"
and Manual Build. You can specify other targets and other triggers. Running your project builder
during auto builds is possible, though not recommended because of performance
concerns. More information about the build kinds can be found here.
Makejar
that is set to run after the default Java builder. Click OK
to save the project builder and close the dialog. The Java builder runs the internal Eclipse Java compiler which in turn is responsible for indexing your source so that searching, refactoring and many other features are available. Thus it is not possible to replace the internal Eclipse Java compiler by using a project builder. You can disable the Java builder and you can control when the Java Builder runs with respect to the project builders that you define.
Creating Ant buildfiles
Project Builder Ant Targets
Editing Ant buildfiles
Saving & Reusing Ant options
Running Ant buildfiles
Ant buildfiles as project builders
Executing project builders
External tools
Non-Ant project builders
Stand-alone external tools