Free tutorials for Java, Eclipse and Web programming



Follow me on twitter

4. Building

PDE Build requires the following configuration files:

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.