Beruflich Dokumente
Kultur Dokumente
Eclipse Tycho - Tutorial for building Eclipse Plugins and RCP applications
Training
Revision History
Books
Revision 0.1
07.08.2011
Lars
Vogel
created
15.06.2013
Lars
Vogel
by Lars Vogel
Eclipse Tycho
This tutorial describes the usage of Eclipse Tycho to build Eclipse Plug-ins and Eclipse RCP applications
This tutorials is based on Eclipse 4.2 and Java 1.6.
Table of Contents
1. Build tools
2. Tycho
2.1. Tycho overview
2.2. pom.xml configuration files
2.3. Source Encoding
2.4. Package attribute
2.5. Target Platform
2.6. Eclipse Maven Integration
2.7. Generating pom files via Tycho
2.8. Defining special build settings
3. Pre-requirements
4. Installation
4.1. Maven command line
4.2. m2eclipse plug-in installation
5. Tutorial: Building Eclipse components
5.1. Overview
5.2. Create master project for the build
5.3. Create projects to build
5.4. Create pom for plug-in project
5.5. Create pom for feature
5.6. Create pom for p2 update site
5.7. Create a JUnit test for the plugin
5.8. Building
6. Building Eclipse products
7. Automatic deployment
8. Thank you
9. Questions and Discussion
10. Links and Literature
10.1. Source Code
10.2. Maven Tycho resources
www.vogella.com/articles/EclipseTycho/article.html
1/12
11/26/13
Eclipse Tycho - Tutorial for building Eclipse Plugins and RCP applications
1. Build tools
A build tool is used to automate repetitive tasks. This can be, for example, compiling source code,
running software tests and creating files and documentation for the software deployment.
Build tools typically run without a graphical user interface (headless) directly from the command line.
Popular build tools in the Java space are Apache Ant, Maven and Gradle.
2. Tycho
2.1. Tycho overview
Eclipse Tycho provides Maven support for building Eclipse components. Tycho is a set of Maven plugins.
Tycho supports the creation of Eclipse Plug-ins, Eclipse features, Eclipse update sites (based on p2) and
building of Eclipse products.
Tycho uses the metadata of the Eclipse components in the MANIFEST.MFfile as much as possible. This
leads to relative small pom.xmlconfiguration files.
The Tycho plug-ins are automatically installed into Maven based on the pom.xmlconfiguration files you
provide.
www.vogella.com/articles/EclipseTycho/article.html
2/12
11/26/13
Eclipse Tycho - Tutorial for building Eclipse Plugins and RCP applications
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho.version}</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<configuration>
<environments>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86</arch>
</environment>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86_64</arch>
</environment>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86</arch>
</environment>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86_64</arch>
</environment>
<environment>
<os>macosx</os>
<ws>cocoa</ws>
<arch>x86_64</arch>
</environment>
</environments>
</configuration>
</plugin>
</plugins>
</build>
</project>
Each modulehas again a pom.xmlconfiguration file which defines attributes specifically to the
corresponding Eclipse component, e.g. the package attribute. The pom.xmlfiles of the modules refer to
their parent pom.xmlfile.
Description
eclipse-plugin
eclipse-feature
eclipse-repository
After setting up your pom.xmlconfiguration files, you can build your Eclipse components with following
commands.
www.vogella.com/articles/EclipseTycho/article.html
3/12
11/26/13
Eclipse Tycho - Tutorial for building Eclipse Plugins and RCP applications
# Switch to the directory
# of you master build file
cd your_master_build_dir
# Alternatively use the following
mvn clean verify
# To get debug output use the -X flag
mvn clean verify -X
Tip
It is not recommened to use the mvn clean installcommand, instead
you should use mvn clean verify. If you would use the installoption,
the build result would be installed in your local Maven repository and this can
lead to build problems.
This will generate a pom for all modules below the current directory and a parent pom in the current
directory. If you want to include Eclipse components which are not in the current directory you can
point Tycho to these directories via the -DextraDirsparameter.
mvn org.eclipse.tycho:tycho-pomgenerator-plugin:generate-poms \
-DgroupId=com.vogella.tycho.build -DextraDirs="../../another_plugin_dir
You can also update existing pom files with the latest version number via the following command.
# update pom files
mvn org.eclipse.tycho:tycho-versions-plugin:update-pom
-Dtycho.mode=maven
www.vogella.com/articles/EclipseTycho/article.html
4/12
11/26/13
Eclipse Tycho - Tutorial for building Eclipse Plugins and RCP applications
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XM
LSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/mav
en-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.vogella.tycho.jgit.plugin</groupId>
<artifactId>de.vogella.tycho.jgit.plugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<properties>
<tycho.version>0.19.0</tycho.version>
<tycho-extras.version>0.19.0</tycho-extras.version>
<kepler-repo.url>http://download.eclipse.org/releases/kepler</kepler-repo.url>
</properties>
<repositories>
<repository>
<id>kepler</id>
<url>${kepler-repo.url}</url>
<layout>p2</layout>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho.version}</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-packaging-plugin</artifactId>
<version>${tycho.version}</version>
<dependencies>
<dependency>
Searchvogella.com Tutorials Training Books Shop Contact us
<groupId>org.eclipse.tycho.extras</groupId>
<artifactId>tycho-buildtimestamp-jgit</artifactId>
<version>${tycho-extras.version}</version>
</dependency>
</dependencies>
<configuration>
<timestampProvider>jgit</timestampProvider>
<jgit.ignore>
pom.xml
</jgit.ignore>
<jgit.dirtyWorkingTree>ignore</jgit.dirtyWorkingTree>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
3. Pre-requirements
The following assumes that you are familiar with Eclipse plug-in and RCP development, e.g. the
creation of plug-ins, features and products. Check Eclipse Plug-in Tutorial and Eclipse RCP Tutorial.
Also see Eclipse Feature Project to learn how to create feature projects.
4. Installation
4.1. Maven command line
The installation of Maven is described on the following website. You need to install Maven3.
http://maven.apache.org/download.html#Installation
www.vogella.com/articles/EclipseTycho/article.html
5/12
11/26/13
Eclipse Tycho - Tutorial for building Eclipse Plugins and RCP applications
http://download.eclipse.org/technology/m2e/releases
www.vogella.com/articles/EclipseTycho/article.html
6/12
11/26/13
Eclipse Tycho - Tutorial for building Eclipse Plugins and RCP applications
<os>linux</os>
<ws>gtk</ws>
<arch>x86_64</arch>
</environment>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86</arch>
</environment>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86_64</arch>
</environment>
<environment>
<os>macosx</os>
<ws>cocoa</ws>
<arch>x86_64</arch>
</environment>
</environments>
</configuration>
</plugin>
</plugins>
</build>
</project>
www.vogella.com/articles/EclipseTycho/article.html
7/12
11/26/13
Eclipse Tycho - Tutorial for building Eclipse Plugins and RCP applications
<packaging>eclipse-feature</packaging>
</project>
5.8. Building
Switch to the directory of your master plug-in and type the following commands to build your
components.
# Switch to the directory
# of you master build file
cd your_master_build_dir
# Alternatively use the following
mvn clean verify
# To get debug output use the -X flag
mvn clean verify -X
www.vogella.com/articles/EclipseTycho/article.html
8/12
11/26/13
Eclipse Tycho - Tutorial for building Eclipse Plugins and RCP applications
In this project you would create a pom.xmlfile which specifies the creation of a p2 update site for your
product and the creation of a zip file.
For example the following shows such a pom.xmlfile.
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<relativePath>../de.vogella.tycho.master/pom.xml</relativePath>
<groupId>com.vogella</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>de.vogella.tycho.rcp.product</artifactId>
<packaging>eclipse-repository</packaging>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-repository-plugin</artifactId>
<version>${tycho.version}</version>
<configuration>
<includeAllDependencies>true</includeAllDependencies>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-director-plugin</artifactId>
<version>${tycho.version}</version>
<executions>
<execution>
<id>materialize-products</id>
<goals>
<goal>materialize-products</goal>
</goals>
</execution>
<execution>
<id>archive-products</id>
<goals>
<goal>archive-products</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
To build a product you need to build your own plug-ins and features. This process is the same as
described earlier. Also the master configuration file is the same.
The following example shows a master pom.xml. In this example your Eclipse RCP application consists
out of one plug-in and one feature.
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.vogella</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>../de.vogella.tycho.rcp.application</module>
<module>../de.vogella.tycho.rcp.feature</module>
<module>../de.vogella.tycho.rcp.product</module>
</modules>
<properties>
<tycho-version>0.19.0</tycho-version>
</properties>
<repositories>
<repository>
<id>kepler</id>
<layout>p2</layout>
<url>http://download.eclipse.org/releases/kepler</url>
</repository>
</repositories>
www.vogella.com/articles/EclipseTycho/article.html
9/12
11/26/13
Eclipse Tycho - Tutorial for building Eclipse Plugins and RCP applications
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>
To ensure that your product can be executed after the build, you have to set the start levels and the
auto-start flag for the following plug-ins in your product configuration file on the Configuration tab,
org.eclipse.core.runtime Start-Level 2
org.eclipse.equinox.ds Start-Level 3
org.eclipse.equinox.event Start-Level 3
7. Automatic deployment
You can use the Maven deployment artifact to deploy your artifacts, e.g. to an ftp server.
Add an entry for the user credentials to your local ~/m2/settings.xmlfile.
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository/>
<interactiveMode/>
<usePluginRegistry/>
<offline/>
<pluginGroups/>
<servers>
<server>
<id>ftp-repository</id>
<username>youruser</username>
<password>yourpassword</password>
</server>
</servers>
<mirrors/>
<proxies/>
<profiles/>
<activeProfiles/>
</settings>
You can then configure your pom.xmlto use the deployment module of Maven.
<project>
<distributionManagement>
<repository>
<id>ftp-repository</id>
<url>ftp://repository.mycompany.com/repository</url>
</repository>
</distributionManagement>
<build>
<extensions>
<!-- Enabling the use of FTP -->
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ftp</artifactId>
<version>1.0-beta-6</version>
</extension>
</extensions>
</build>
</project>
The following command will now deploy your artifacts to your ftp site.
mvn deploy
If you only want to upload your p2 update site, you can configure the org.apache.maven.wagon
www.vogella.com/articles/EclipseTycho/article.html
10/12
11/26/13
Eclipse Tycho - Tutorial for building Eclipse Plugins and RCP applications
plug-in.
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<relativePath>../de.vogella.tycho.master/pom.xml</relativePath>
<groupId>com.vogella</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>de.vogella.tycho.p2updatesite</artifactId>
<packaging>eclipse-repository</packaging>
<name>Tycho Test Build</name>
<build>
<extensions>
<!-- Enabling the use of FTP -->
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ftp</artifactId>
<version>1.0-beta-6</version>
</extension>
</extensions>
</build>
<profiles>
<!-- This profile is used to upload the repo -->
<profile>
<id>uploadRepo</id>
<properties>
<!-- Properties relative to the
distant host where to upload the repo -->
<ftp.url>ftp://your.server.com</ftp.url>
<ftp.toDir>/yourpath</ftp.toDir>
<!-- Relative path to the repo being uploaded -->
<repo.path>${project.build.directory}/repository/</repo.path>
</properties>
<build>
<plugins>
<!-- Upload the repo to the server -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
<version>1.0-beta-4</version>
<executions>
<execution>
<id>upload-repo</id>
<phase>install</phase>
<goals>
<goal>upload</goal>
</goals>
<configuration>
<fromDir>${repo.path}</fromDir>
<includes>**</includes>
<toDir>${ftp.toDir}</toDir>
<url>${ftp.url}</url>
<serverId>p2Repo</serverId>
<!-- Points to your settings.xml
where the connection settings are
stored as shown below -->
<!-- <server> -->
<!-- <id>p2Repo</id> -->
<!-- <username>username</username> -->
<!-- <password>password</password> -->
<!-- </server> -->
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
You can now upload your p2 update site with the following command.
mvn install -P uploadRepo
www.vogella.com/articles/EclipseTycho/article.html
11/12
11/26/13
Eclipse Tycho - Tutorial for building Eclipse Plugins and RCP applications
8. Thank you
Please help me to support this article:
www.vogella.com/articles/EclipseTycho/article.html
12/12