Eclipse RCP Entwicklung mit Tycho (Teil 2)
08.08.2010 | Kategorie: Softwareentwicklung | 2 Kommentare | Kommentar Feed | Trackback
Die im ersten Teil erstellte Eclipse RCP Anwendung wird nun mit den notwendigen pom.xml Dateien versehen. Bevor wir damit starten, muss der Product Export getestet werden. Kann die Anwendung danach erfolgreich gestartet werden, so können wir mit der Generierung bzw. Erstellung der POM’s starten. Die Eclipse Projekte selbst werden nicht weiter verändert!
Die Generierung der pom.xml Dateien kann durch Tycho erfolgen. Dazu wird in dem Verzeichnis, welches die Eclipse Projekte enthält, das folgende Kommando ausgeführt:
mvn3 org.sonatype.tycho:maven-tycho-plugin:generate-poms -DgroupId=de.kofaldt
Dies erstellt uns eine initiale Parent pom.xml. Gleiches gilt für das Plugin und das Feature Projekt. Um das Product und das Target Projekt müssen wir uns selber kümmern. Auch sind die erzeugten POM’s noch nicht komplett. Insbesondere die Parent POM muss ergänzt werden.
Diese wollen wir als erstes nachbessern. Dort wird auch festgelegt für welche Plattformen die Anwendung später erstellt werden soll. In meinem Beispiel sind dies Linux, Mac OS und Windows:
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>de.kofaldt</groupId>
<artifactId>rcp-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<tycho.version>0.9.0</tycho.version>
</properties>
<modules>
<module>de.kofaldt.rcp.sample</module>
<module>de.kofaldt.rcp.sample.feature</module>
<module>de.kofaldt.rcp.sample.plugin</module>
<module>de.kofaldt.rcp.sample.target-platform</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.sonatype.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho.version}</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.sonatype.tycho</groupId>
<artifactId>maven-osgi-compiler-plugin</artifactId>
<version>${tycho.version}</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.sonatype.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho.version}</version>
<configuration>
<resolver>p2</resolver>
<target>
<artifact>
<groupId>de.kofaldt</groupId>
<artifactId>de.kofaldt.rcp.sample.target-platform</artifactId>
<version>3.6.0-SNAPSHOT</version>
<classifier>helios</classifier>
</artifact>
</target>
<environments>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86</arch>
</environment>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86_64</arch>
</environment>
<environment>
<os>macosx</os>
<ws>cocoa</ws>
<arch>x86_64</arch>
</environment>
</environments>
<ignoreTychoRepositories>false</ignoreTychoRepositories>
</configuration>
</plugin>
</plugins>
</build>
</project>Das Projekt, welches die Target Definition enthält, wird mit dieser pom.mxl versehen:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.kofaldt</groupId>
<artifactId>rcp-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>de.kofaldt</groupId>
<artifactId>de.kofaldt.rcp.sample.target-platform</artifactId>
<version>3.6.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Helios RCP Target platform</name>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>helios.target</file>
<type>target</type>
<classifier>helios</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>Die ausstehenden POM’s sind wesentlich kompakter. Für das Plugin Projekt lautet sie:
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.kofaldt</groupId>
<artifactId>rcp-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>de.kofaldt</groupId>
<artifactId>de.kofaldt.rcp.sample.plugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>Die pom.xml für das Feature Projekt:
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.kofaldt</groupId>
<artifactId>rcp-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>de.kofaldt</groupId>
<artifactId>de.kofaldt.rcp.sample.feature</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-feature</packaging>
</project>Und zum Schluss die pom.xml für das Projekt mit der Product Definition. Dabei ist zu beachten, dass Tycho die Product Definition unter dem Namen <artifactId>.product sucht und momentan nicht konfiguriert werden kann:
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.kofaldt</groupId>
<artifactId>rcp-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>de.kofaldt</groupId>
<artifactId>de.kofaldt.rcp.sample</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-application</packaging>
</project>Mit diesen Änderungen lässt sich nun per Maven und Tycho die Eclipse RCP Anwendung bauen. Im Verzeichnis der Parent POM wird nun das folgende Kommando abgesetzt:
mvn clean install
Die Erstellung nimmt beim ersten Mal etwas Zeit in Anspruch, da die notwendigen Tycho Plugins sowie die Target Platform heruntergeladen werden müssen. Am Ende wird die Anwendung aber erfolgreich erstellt und Maven verabschiedet sich mit einer Erfolgsmeldung:
[INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary: [INFO] [INFO] rcp-parent ........................................ SUCCESS [19.840s] [INFO] de.kofaldt.rcp.sample.plugin ...................... SUCCESS [55.305s] [INFO] de.kofaldt.rcp.sample.feature ..................... SUCCESS [0.316s] [INFO] de.kofaldt.rcp.sample ............................. SUCCESS [4.129s] [INFO] Helios RCP Target platform ........................ SUCCESS [26.999s] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2:12.062s [INFO] Finished at: Sat Aug 07 22:28:47 CEST 2010 [INFO] Final Memory: 64M/356M [INFO] ------------------------------------------------------------------------
Die fertig gebaute Anwendung liegt im Projekt, welches die Product Definition enthält. Wie in der Parent pom festgelegt, finden wir für die drei Plattformen die fertigen Pakete:

Es fehlt die Prüfung, ob sich die Anwendung auch tatsächlich starten lässt:

Fazit
Mit Tycho lassen sich Eclipse RCP Anwendungen bauen. Die Umstellung bestehender Projekte ist unkompliziert und wird sich demnächst wohl noch vereinfachen. So wird die Tycho Entwicklung demnächst unter dem Eclipse Dach stattfinden. Ein Proposal dazu existiert und das erste Release ist bereits für Q3 2010 geplant.
Auch wenn noch nicht alles so funktioniert wie man es von Maven gewohnt ist, bietet Tycho mit dem Manifest-first Ansatz einen einfachen Zugang um Eclipse Anwendungen zu bauen. Dies gilt für einfache sowie für komplexe Anwendungen.
Wer bisher Maven Projekte über einen Continous Integration Server, wie z.B. Hudson, erstellt hat und einen Weg suchte Eclipse Anwendungen ebenfalls so zu erstellen, kann dies nun mit Tycho realisieren.
2 Kommentare
Kommentar hinterlassen
Es kann sein, dass dein Kommentar zuerst in die Kommentar-Warteschlange gelangt, danach muss er zuerst von mir freigeschaltet werden. Dies geschieht im Normalfall nach maximal 24h.
Hallo André,
ich habe Deinen Artikel mit Interesse gelesen und nachvollzogen.
Eine kleine Abweichung habe ich aber doch vorgenommen, in der Annahme, dass es keine Auswirkung haben möge. Ich habe das Feature-Projekt weggelassen.
Meine Entwicklungsumgebung ist Windows-XP (32-bit).
Das Produkt für diese Umgebung lässt sich mit Maven erstellen und ist auch lauffähig.
Für die anderen Platformen bekomme ich jedoch eine Fehlermeldung (bei clean und install):’No solution found because the problem is unsatisfiable.’
Hier wird für die Platform ‘osgi.ws=gtk, osgi.arch=x86_64, osgi.os=linux’ das Plugin ‘org.eclipse.swt.win32.win32.x86 0.0.0′ vermisst (Soll ja auch nicht rein, meine ich)
Bevor ich das Produkt erstellen konnte, musste ich jedoch im Produkt die Dependencies erstellen (Add Required Plugins). Dabei sind Plattform-Abhängigen win32 Plugins hinzugekommen.
Wenn ich diese Dependencies wegnehme, werden in keinem Ergebnis diese Platform abhängigen Plugins eingefügt.
Kannst Du mir sagen, wo mein Fehler liegt?
Vielen dank Roland
Hallo,
ein wunderbares Tutorial, das mich auf den richtigen Weg mit Tycho gebracht hat! Ein kleines Update, das für andere Leser interessant (und wichtig) sein dürfte: Tycho ist ja jetzt ein Eclipse Project, insofern wäre der erste Schritt (das Erstellen der POMs) neuerdings wie folgt zu verwenden:
mvn org.eclipse.tycho:tycho-pomgenerator-plugin:generate-poms -DgroupId= …
Vielen Dank & Grüße,
Stephan