blob: 75595016de8ab4373fdf17f623a68f9ab696f0e7 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML>
<HEAD>
<meta name="copyright" content="Copyright (c) IBM Corporation and others 2000, 2005. This page is made available under license. For full details see the LEGAL in the documentation book that contains this page." >
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
<LINK REL="STYLESHEET" HREF="../book.css" CHARSET="ISO-8859-1" TYPE="text/css">
<title>Creating a project builder Ant buildfile</title>
</HEAD>
<BODY BGCOLOR="#ffffff">
<h3>Creating a project builder Ant buildfile</h3>
<P CLASS="Para">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.</P>
<ol>
<li>Create a Java project named 'HW'.</li>
<li>Create a Java source file named 'HelloWorld' with a main method.</li>
<li>Put a single 'System.out.println()' statement in the main method, and make
it print a greeting of your choice.</li>
<li>Save changes.</li>
<li>Create a file named 'projectBuilder.xml', open the Ant editor on it, enter
the following content, and save changes.<br>
<pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;project name="HW.makejar" default="makejar" basedir="."&gt;
&lt;target name ="makejar" description="Create a jar for the HW project"&gt;
&lt;jar jarfile="HelloWorld.jar" includes="*.class" basedir="."/&gt;
&lt;/target&gt;
&lt;/project&gt;</pre>
</li>
<li>In one of the navigation views, select the HW project and choose <b>Properties</b>
from its context menu.</li>
<li>In the project properties dialog, select <b>Builders</b>, then click <b>New...</b>.
</li>
<li>In the <strong>Choose configuration type</strong> dialog, select <strong>Ant
build</strong>, and click <b>OK</b>. </li>
<li>The <strong>External Tools</strong> dialog appears. Set the name to 'Makejar'.
In the Main tab, click the <strong>Buildfile</strong> <b>Browse Workspace...</b>
and set the <b>Location</b> to be the projectBuilder.xml buildfile created
above. Then click the <strong>Base Directory</strong> <b>Browse Workspace...</b>
and set the Base Directory to be the HW project.<br>
<img src="../images/Image611_et_main_tab.png" alt="Main tab of External tools dialog" border="0" >
</li>
<li>In the <b>Refresh</b> tab, we want to be sure that when our HelloWorld.jar
is created, we see it in Eclipse. By default, no refreshing is done when a
project builder finishes running, so check <b>Refresh resource upon completion</b>,
then select <b>The project containing the selected resource</b> in the list
of scope 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. <br>
<img src="../images/Image612_et_refresh_tab.png" alt="Refresh tab of External tools dialog" border="0" >
</li>
<li>In the <b>Targets</b> tab, you can specify when this project builder
is executed and which targets. By default, the default target is set to run <strong>After a &quot;Clean&quot;
</strong>and <strong>Manual Build</strong>. You can specify other targets and other triggers. Running your project builder
during auto builds is possible, though not recommended because of performance
concerns.<br>
<img src="../images/Image610_et_targets_tab.png" alt="Targets tab of External tools dialog" border="0" >
</li>
<li>Apply the changes and click <b>OK</b>.</li>
<li>Back in the project properties dialog, you will now see a project builder
named 'Makejar' that is set to run after the default Java Builder. Click <b>OK</b>
to save the project builder and close the dialog. <strong><br>
Note: </strong>You can change the order so that your Ant buildfile runs before
the Java builder, though that wouldn't make sense in this example. <br>
<img src="../images/Image613_project_properties.png" alt="Project properties dialog" border="0" >
</li>
</ol>
<p>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.</p>
</BODY>
</HTML>