Java, Eclipse and Web programming Tutorials

Eclipse PDE Build - Tutorial

Lars Vogel and Dominik Zapf

Version 1.3

22.10.2009

Revision History
Revision 0.115.09.2008Lars Vogel
First draft of article
Revision 0.220.11.2008Dominik Zapf
Added ant description
Revision 0.330.11.2008Lars Vogel
Corrections
Revision 0.410.12.2008Dominik Zapf
Corrections
Revision 0.527.12.2008Lars Vogel
Created separate article for PDE build, fixed description
Revision 0.630.12.2008Lars Vogel
Feature build now works
Revision 0.711.01.2009Lars Vogel
Simplified the build example
Revision 0.812.01.2009Lars Vogel
Minor adjustments
Revision 0.927.07.2009Lars Vogel
Started update to Eclipse 3.5
Revision 1.028.07.2009Lars Vogel
Update to Eclipse 3.5
Revision 1.105.09.2009Lars Vogel
Fixed error with location of build.mxl
Revision 1.210.09.2009Lars Vogel
reworked article
Revision 1.322.10.2009Lars Vogel
Removed hard-coded I.TestBuild from build.xml

Eclipse PDE build

This article describes how to use Eclipse PDE Build to create automatically a running application from source code.

This article uses Eclipse 3.5 and Java 1.6.


Table of Contents

1. Eclipse PDE/Build
2. Eclipse Deltapack
2.1. Download
2.2. Target Platform
3. Create your application
3.1. Pre-requirements
3.2. Create plugin and feature
4. Building
4.1. Create project
4.2. Configuration file
4.3. Run the build
4.4. Test your build result
5. Thank you
6. Questions and Discussion
7. Links and Literature
7.1. Source Code
7.2. PDE/Build links

1. Eclipse PDE/Build

PDE/Build is a Apache Ant based build system for Eclipse RCP application and Eclipse plugins. This build system is also called "headless" build because it does not require a running Eclipse UI to create your product.

The PDE build system is part of the Eclipse plugin org.eclipse.pde.build.

Tip

This tutorial will use the Ant functionality inside Eclipse and does not require a separate Ant installation. To run PDE/Build outside Eclipse you need to have Ant separately installed (see Apache Ant for details.

This tutorial uses PDE build to create a executable application for an Eclipse RCP project.

Tip

Check also the PDE build help in the Eclipse help under Help -> Help Contents -> Plug-in Development Environment Guide -> Tasks

2.  Eclipse Deltapack

2.1.  Download

The delta pack is required to use PDE/build.

This deltapack contains the platform specific features and plugins which are required for building Eclipse product for all platforms. It also includes binary launchers for all platforms in the feature "org.eclipse.equinox.executable".

Tip

The deltapack is also required to export your product for multiple platform via the user interface. See Interactive deployment of Eclipse RCP products .

The deltapack can be found http://download.eclipse.org/eclipse/downloads/ . Select the release for are interested in, e.g. 3.5 and search on the page for "Delta".

Extract the delta pack to a new directory, I recommend to use eclipse install directory and then "/deltapack/eclipse/". So if you installation directory is c:\eclipse35 then it should look like the following.

2.2.  Target Platform

To make the delta pack available to the Eclipse IDE add it to the target platform under Windows-> Preferences-> Plug-in Development -> Target Platform. Edit the exiting target platform and add the directory of the delta pack to it.

3. Create your application

3.1.  Pre-requirements

The following assumes that you are familiar with Eclipse RCP development, e.g. the creation of plugins, features and products. Check Eclipse RCP Tutorial to learn about RCP development. See Eclipse Feature Project to learn how to create feature projects.

PDE/Build requires features based products. In our example we will create one plugin and then a feature which includes this plugin.

3.2.  Create plugin and feature

Create a new project "de.vogella.build.ui" using the "RCP application with a view" template. See Eclipse RCP Tutorial for details.

Create a feature project "de.vogella.build.feature" which contains the plugin de.vogella.build.ui. See Eclipse Feature Project

Add the plugin "de.vogella.build.ui" to your feature.

Also add the "org.eclipse.rcp" to "Included Feature".

Create a product called "hellorcp.product" in "de.vogella.build.ui". See Create a Eclipse product for information.

Make sure your product runs correctly can can be exported manually via the "Export Product export wizard" in the product. If the manually exported product runs you are ready for the next step in creating a automatic product build.

4. Building

PDE Build requires the following configuration files:

  • build.properties

  • build.xml - ant build script

Tip

The standard Eclipse installation has templates for these files in the directory templates\headless-build in the plugin org.eclipse.pde.build.

4.1. Create project

Create a separate project for your build. Create therefore a general project "de.vogella.build.script" by File -> New -> Project -> General -> Project (not using any template / reference).

4.2.  Configuration file

Create the file "build.properties". This file define settings for the build process.

Table 1. 

ElementDescription
productthe product your are building, e.g. /de.vogella.build.ui/hellorcp.product
configs The platform you are building for, e.g. Windows
JavaSE-1.6 This example uses Java 1.6

Here is the build.properties for this example

				
###############################################################################
# Copyright (c) 2003, 2006 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
# 
# Contributors:
#     IBM Corporation - initial API and implementation
###############################################################################
product=/de.vogella.build.ui/hellorcp.product
runPackager=true

p2.gathering=true
		p2.metadata.repo=file:${builder}/repository
p2.artifact.repo=file:${builder}/repository

#Set the name of the archive that will result from the product build.
#archiveNamePrefix=

# The prefix that will be used in the generated archive.
archivePrefix=yourproduct

# The location underwhich all of the build output will be collected.
collectingFolder=${archivePrefix}

# The list of {os, ws, arch} configurations to build.  This 
# value is a '&' separated list of ',' separate triples.  For example, 
#     configs=win32,win32,x86 & linux,motif,x86
# By default the value is *,*,*
configs = win32, win32, x86
#configs=win32, win32, x86 & \
#	linux, gtk, ppc &\
# linux, gtk, x86 & \
#	linux, gtk, x86_64 & \
#	linux, motif, x86 & \
#	solaris, motif, sparc & \
#	solaris, gtk, sparc & \
#	aix, motif, ppc & \
#	hpux, motif, PA_RISC & \
#	macosx, carbon, ppc

#Allow cycles involving at most one bundle that needs to be compiled with the rest being binary bundles.
allowBinaryCycles = true

# Type of build.  Used in naming the build output.  Typically this value is
# one of I, N, M, S, ...
buildType=I

# ID of the build.  Used in naming the build output.
buildId=TestBuild

# Label for the build.  Used in naming the build output
buildLabel=${buildType}.${buildId}

# Timestamp for the build.  Used in naming the build output
timestamp=007

#this property indicates whether the resolution should be done in development mode (i.e. ignore multiple bundles with singletons)
resolution.devMode=false

skipBase=true
skipMaps=true
skipFetch=true


############# JAVA COMPILER OPTIONS ##############
# For this example:
# We specify the JRE locations for CDC-1.1/Foundation-1.1 and J2SE-1.5
# because these are the required execution environments defined for the 
# bundles in the example. 

# The location of the Java jars to compile against.  Typically the rt.jar for your JDK/JRE
#bootclasspath=${java.home}/lib/rt.jar

# If using an IBM VM, use
#bootclasspath=${java.home}/lib/core.jar;${java.home}/lib/vm.jar

# specific JRE locations to compile against. These values are used to compile bundles specifying a 
# Bundle-RequiredExecutionEnvironment. Uncomment and set values for environments that you support
#CDC-1.0/Foundation-1.0= /path/to/rt.jar
CDC-1.1/Foundation-1.1=${java.home}/lib/rt.jar
#OSGi/Minimum-1.0=
#OSGi/Minimum-1.1=
#JRE-1.1=
#J2SE-1.2=
#J2SE-1.3=
#J2SE-1.4=
#J2SE-1.5=${java.home}/lib/rt.jar
JavaSE-1.6=${java.home}/lib/rt.jar
#PersonalJava-1.1=
#PersonalJava-1.2=
#CDC-1.0/PersonalBasis-1.0=
#CDC-1.0/PersonalJava-1.0=
#CDC-1.1/PersonalBasis-1.1=
#CDC-1.1/PersonalJava-1.1=

# Specify the output format of the compiler log when eclipse jdt is used
logExtension=.log

# Whether or not to include debug info in the output jars
javacDebugInfo=false 

# Whether or not to fail the build if there are compiler errors
javacFailOnError=true

# Enable or disable verbose mode of the compiler
javacVerbose=true

# Extra arguments for the compiler. These are specific to the java compiler being used.
#compilerArg=

# Default value for the version of the source code. This value is used when compiling plug-ins that do not set the Bundle-RequiredExecutionEnvironment or set javacSource in build.properties
#javacSource=1.3

# Default value for the version of the byte code targeted. This value is used when compiling plug-ins that do not set the Bundle-RequiredExecutionEnvironment or set javacTarget in build.properties.
#javacTarget=1.1



			

Create the following ant build file "build.xml".

				
<project default="main">
	<property file="build.properties"/>
	<target name="main">
		<property name="baseLocation" value="${eclipse.home}"/>
		<!-- by default, check for deltapack co-located with eclipse -->
		<property name="deltapack" value="${eclipse.home}/deltapack/eclipse"/>

		<!-- Check that we have a deltapack -->
		<available property="haveDeltaPack" file="${deltapack}"/>
		<fail unless="haveDeltaPack" message="The deltapack is required to build this product.  Please edit buildProduct.xml or set the &quot;deltapack&quot; property." />
			
		<property name="builder" value="${basedir}" />
		<property name="buildDirectory" value="${basedir}/buildDirectory"/>
		<property name="pluginPath" value="${basedir}/..${path.separator}${deltapack}" />
		<property name="buildTempFolder" value="${buildDirectory}" />
			
		<ant antfile="${eclipse.pdebuild.scripts}/productBuild/productBuild.xml" />

		<move todir="${basedir}">
			<fileset dir="${buildDirectory}/${buildLabel}" includes="*.zip"/>
		</move>

		<!-- refresh the workspace -->
		<eclipse.convertPath fileSystemPath="${basedir}" property="resourcePath"/>
		<eclipse.refreshLocal resource="${resourcePath}" depth="infinite"/>
	</target>
</project>
			

The result should look like the following:

4.3.  Run the build

Right-click the build.xml in Eclipse and choose Run as --> External Tools Configuration. Create a runtime configuration and make sure that you select "Run in the same JRE as the workspace". This will make sure that the variables, e.g. eclipse_home in file buildProduct.xml are set.

4.4.  Test your build result

In your build folder you should have a zip file, called "TestBuild-win32.win32.x86.zip". Extract it somewhere in your file system and try to start the product. If everything worked correctly then it should start without problems.

5. Thank you

Thank you for practicing with this tutorial.

Please note that I maintain this website in my private time. If you like the information I'm providing please help me by donating.

6. Questions and Discussion

For questions and discussion around this article please use the www.vogella.de Google Group. Also if you note an error in this article please post the error and if possible the correction to the Group.

I believe the following is a very good guideline for asking questions in general and also for the Google group How To Ask Questions The Smart Way.

7. Links and Literature

7.1. Source Code

http://www.vogella.de/code/codeeclipse.html Source Code of Examples

7.2. PDE/Build links

http://wiki.eclipse.org/Equinox/p2/Publisher P2 publisher

http://aniefer.blogspot.com/ Blog from PDE Build developer Andrew Niefer

http://aniefer.blogspot.com/2009/03/building-p2-rcp-products-in-eclipse.html Andrew Niefer's example for PDE build for RCP applications

http://wiki.eclipse.org/Equinox/p2/Adding_Self-Update_to_an_RCP_Application Adding p2 Update to an Eclipse RCP application

http://download.eclipse.org/eclipse/downloads/ Download site from Eclipse containing also the Delta Packs

www.eclipse.org/pde/pde-build Eclipse PDE/Build