Skip to Content

<buildJdtProject>

Scope: JDT Projects

Description

This macro builds an Eclipse Java (JDT) project. It reads all informations needed to build the project (classpath, project directory structure, compiler settings etc) from the standard eclipse configuration files like .classpath and .settings-files. The project is compiled using the Eclipse java compiler.

Important: This task is implemented as an Ant macro. To use this task, you have to import the file 'a4e-jdt-macros.xml' in your build file.

Arguments

The buildPlugin task provides the following arguments:

Argument Description Required
workspaceDirectory Absolute path of the workspace directory Either 'workspaceDirectory' or 'workspaceId' has to be specified
workspaceId The identifier of a defined workspace (see <workspaceDefinition>) Either 'workspaceDirectory' or 'workspaceId' has to be specified
projectName Name of the eclipse project that you want to build yes
targetPlatformId The id of the target platform. no, only in case your project (or one of it's dependencies) is a PDE plug-in project
defaultCompilerOptionsFile The location of a properties file that contains the settings for the eclipse compiler. This settings will be used if no project-specific settings file is available.  This option also allows to handle an exported eclipse preferences file. no
targetLevel The language level of the generated bytecode (e.g. 1.4 or 1.5) no
sourceLevel The language level of the source files (e.g. 1.4 or 1.5) no, defaults to the specified targetLevel
useEcj Enables or disables the use of the ecj compiler as the backend. no, default to true

A note on compiler settings: You should either use defaultCompilerOptionsFile or targetLevel/sourceLevel. If you both the defaultCompilerOptionsFile takes precedence over the targetLevel/sourceLevel-argument.

Lifecycle hooks

To allow the user of ant4eclipse to add additional build steps to the build process, the buildJdtProject macro defines the following lifecycle hooks that are implement as macro elements.

Build phase Description Required
initialize Initialize build state, e.g. set properties or create directories. no
generate-sources Generate any source code for inclusion in compilation. no
generate-resources Generate resources for inclusion in the package. no
pre-compile Execute additional steps before compilation. no
post-compile Post-process the generated files from compilation, for example to do bytecode enhancement on Java classes.. no
finish Finish the build process. This can be used to take further actions, like packaging the project no

Scoped properties

The following scoped properties are available within the lifecycle hooks:

Property Description Build phase
buildJdtProject.project.name The name of the project All phases
buildJdtProject.project.directory Absolute path of the project directory All phases
buildJdtProject.<project nature name> true (this property is set for each project nature the project contains) All phases
buildJdtProject.boot.classpath The boot class path of the used JRE. All phases
buildJdtProject.classpath.relative.runtime The runtime class path of the JDT project, relative to the workspace location. All phases
buildJdtProject.classpath.absolute.runtime The absolute runtime class path of the JDT project. All phases
buildJdtProject.classpath.relative.compiletime The compile time class path of the JDT project, relative to the workspace location. All phases
buildJdtProject.classpath.absolute.compiletime The absolute compile time class path of the JDT project. All phases
buildJdtProject.default.output.directory The absolute path of the default ouput directory. All phases
buildJdtProject.default.output.directory.name The name of the default ouput directory. All phases
buildJdtProject.source.directories The source directories (only set if the project contains source directories) All phases

Scoped references

The following scoped references are available:

Reference Description Build phase
buildJdtProject.project.directory.path The project directory as an ant path All phases
buildJdtProject.boot.classpath.path The boot class path of the used JRE. All phases
buildJdtProject.classpath.relative.runtime.path The runtime class path of the JDT project, relative to the workspace location. All phases
buildJdtProject.classpath.absolute.runtime.path The absolute runtime class path of the JDT project. All phases
buildJdtProject.classpath.relative.compiletime.path The compile time class path of the JDT project, relative to the workspace location. All phases
buildJdtProject.classpath.absolute.compiletime.path The absolute compile time class path of the JDT project. All phases
buildJdtProject.default.output.directory.path The absolute path of the default ouput directory. All phases
buildJdtProject.source.directories.path The source directories (only set if the project contains source directories) All phases

Example usage

The following example builds the jdt project with the project name 'example-project'. It will use the java version 1.5 if there is no project specific compiler settings file inside the project:

<buildJdtProject workspaceDirectory="${workspaceDirectory}" 
  projectName="example-project"
  targetLevel="1.5"/>

This example uses the jdtProjectFileSet in the finish phase to build a jar containing the project's classes that have been built:

<buildJdtProject workspaceDirectory="${workspaceDirectory}" 
  projectName="example-project"
  targetLevel="1.5">
  <finish>
    <jar destfile="c:/example-project.jar">
      <ant4eclipse:jdtProjectFileSet
        workspaceDirectory="${workspaceDirectory}"
        projectName="${buildJdtProject.project.name}"/>
    </jar>
  </finish>		
</buildJdtProject>