Configuring Eclipse PDT to work with Ant build tasks

by Klaus Graefensteiner 22. April 2010 08:27

Introduction

This is the seventh article of a series of blog post called the WIMPinator Chronicles that describe how to setup a PHP development environment for Windows 7 and IIS 7.5.

So far we covered how to install a Wordpress blog and all its dependencies using the WPI (Web Platform Installer). Then we added additional features and extensions to the PHP deployment on Windows for IIS. I explained how to get PEAR setup and how to download and deploy the PHPUnit unit testing framework using PEAR. In the next two posts I described how to install Eclipse PDT and make it work with Subversion source control using Subclipse. In the most recent post I explained how to create an IIS 7.5 Fast CGI web site from scratch.

This tutorial covers how to use ANT build tasks to deploy your PHP project from Eclipse to your IIS test server using custom build steps.

The Series

  1. Getting a Wordpress blog installed in a jiffy on Windows 7 using the Web Platform Installer
  2. Adding additional features to PHP
  3. Installing PEAR and PHPUnit
  4. Installing Eclipse PDT
  5. Configuring Eclipse PDT to work with Subversion source control
  6. Creating a new IIS 7.5 fast CGI web site
  7. Configuring Eclipse to work with Ant build tasks
  8. Setting up XDebug with Eclipse and IIS 7.5
  9. Setting up the Zend Debugger with Eclipse and IIS 7.5
  10. Configuring Ruby and Watir
  11. Moving a Wordpress blog from GoDaddy shared hosting to my local debugging system.
  12. NEW: Setting up the CodeIgnitor MVC framework with PDT and IIS 7.5
  13. NEW: Configuring IIS 7.5 Rewrite rules to exclude index.php from the URL
  14. NEW: Configuring SSL on IIS 7.5
  15. NEW: Writing unit tests with PHP Unit
  16. NEW: Writing web UI tests with Watir

References

While searching the interweb about this topic I found the following tutorial:

http://individual.utoronto.ca/kia/

Add Ant to Eclipse PDT

To move the php and html files to your test and production IIS web site from Eclipse you would use Ant build tasks. Unfortunately Ant is not installed by default in Eclipse PDT. But it comes with the standard version of Eclipse. In fact it is part of the Java development plug-in.

To install the Java plug-in go to the Eclipse menu Help\Install New Software.

image_60

Figure 1: Go to the Eclipse Help\Install Software Menu

Select Galileo from the “Work with” drop down list.

image_62

Figure 2: Choose Galileo

Expand the Programming Languages node and select Eclipse Java Development Tools.

image_86

Figure 3: Select the Eclipse Java Development Tools

Click Next to get to the Install Details dialog.

image_96

Figure 4: Click next to confirm the Install Details

Accept the Eula.

image_98

Figure 5: Accept the license agreement

The download and installation starts after you click the Finish button.

image_100

Figure 6: Installing the Java development plug-in

At the end of the installation you might be asked to restart Eclipse. Click No and then restart Eclipse manually.

image_102

Figure 7: Click No and restart Eclipse manually

Create your first Ant task

First create a new XML file and name it for example MoveToIISTask.xml.

image_104

Figure 8: Create new XML file

Right click on new xml file and select open with other…. This will open the Editor Selection dialog.

 image_136

Figure 9: Open the XML file and select Other…

In the Edit Selection dialog select Ant Editor.

 image_138

Figure 10: Select the Ant Editor

Create a copy task. Use the Ant manual for help. Search for File Tasks. 

image_80

Figure 11: Screenshot of an Ant copy task

You could copy and past the following snippet and modify it for your needs:

<?xml version="1.0" encoding="UTF-8"?>
<project name="CIM225" default="CopySite" basedir=".">
	<property name="IIS Virtual Directory" value="c:/inetpub/wwwroot/cim225/"/>
    <target name="CopySite">
        <echo>${IIS Virtual Directory}</echo>
	  	<copy todir= "${IIS Virtual Directory}">
	    	<fileset dir=".">
	      		<include name="**/*.php"/>
		  		<include name="**/*.html"/>
		  		<include name="**/*.txt"/>
	    		<include name="**/*.css"/>
	    		<include name="**/*.js"/>
	    		<include name="**/*.gif"/>
	    		<include name="**/fruitdbbackup.sql"/>
	    		<include name="**/*.zip"/> 
	    	</fileset>
	  	</copy>
	</target>
</project>

Hooking up the build task script with an Eclipse Builder

Now select your project and press Alt + Enter (Right mouse click “Properties”).

image_140

Figure 12: Go to the project properties

Go to the Builders node in the Properties dialog.

image

Figure 13: Select the Builders node

Click the New button to create a new Builder and select Ant Builder from the Choose configuration type dialog.

 image_144

Figure 14: Choose the Ant Builder 

Give the Builder a name in the Edit Configuration dialog.

image_146

Figure 15: Name your Builder

Now select a Build file using the Browse Workspace button. Choose the MoveTOIISTask.xml file in the Choose Location dialog.

 image_148

Figure 16: Select the Ant build task xml file

Also select a Base Directory using the respective Browse Workspace button.

image_150

Figure 17: Use the Browse Workspace button to select the project folder as Base Directory

The Builder configuration is now complete and the finished dialog should look like this.

image_152

Figure 18: Build task is now complete

Closing this dialog by clicking OK will result in the following list of Builders.

 image_154

Figure 19: New Builder has been added to list

Executing the new build task

In order to execute this Ant task, select your project and go to Project Build All (Ctrl+B).

image_156

Figure 20: Start a build with Ctrl+B

The build will now copy the selected files to the IIS application folder and the result is displayed in the Eclipse console window.

image_158 

Figure 21: Build (copy files) completes successfully

Note: Make sure that you have sufficient permissions to access the IIS7 virtual directory (Inetpub\wwwroot\cim225). Otherwise you will get an access violation error during the copy process.

Note: If nothing in the project has changed since the last build, the ant task will not be executed.

Ausblick

This concludes this part of the WIMPinator tutorial. The build steps can still be improved. Here are some tasks that I’d like to add:

  • Create a debug, stage and production deployment step
  • Launch web site in default browser
  • Execute PHPUnit unit tests
  • Execute Watir (Ruby) web ui tests

In the next two blog posts I am going to write about how to setup the Zend and XDebug extension to use with Eclipse.

Stay tuned!

Tags: , , , , ,

Tips & Tricks | WIMPinator Chronicles | Php | Test Automation | Java | IIS | Eclipse

Comments

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading



About Klaus Graefensteiner

I like the programming of machines.

Add to Google Reader or Homepage

LinkedIn FacebookTwitter View Klaus Graefensteiner's profile on Technorati
Klaus Graefensteiner

Klaus Graefensteiner
works as developer in Test at Rockwell Automation and is founder of the PowerShell Unit Testing Framework PSUnit. More...

Administration

About

Powered by:
BlogEngine.Net
Version: 1.5.0.7

License:
Creative Commons License

Copyright:
© Copyright 2009, Klaus Graefensteiner.

Disclaimer:
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Theme design:
This blog theme was designed and is copyrighted 2009 by Klaus Graefensteiner

Rendertime:
Page rendered at 9/8/2010 10:00:53 AM (PST Pacific Standard Time UTC DST -7)