Tutorial: Eclipse RCPs mit Maven

By breskeby | August 9, 2007

===Ziel===
In diesem Beitrag möchte ich zeigen wie man Build Läufe einer EclipseRCP Applikation mit Maven automatisieren kann.
Das Tutorial basiert auf dem howto vom pde-maven-plugin, welches allerdings einige kleinere Fallen bereit hält.

===EntwicklungsUmgebung===
Im Beispiel verwende ich Eclipse 3.3 (Europe). Ausserdem wird das Delta Pack für Eclipse 3.3 benötigt. Als Ziel und Entwicklungsplattform nutze ich Windows XP. Der Einfachheit halber habe ich das Delta Pack direkt in meine Eclipse Installation abgelegt und keine eigene Target-Platform angelegt. Neben dem Eclipse Zeugs sollte natürlich auch Maven installiert sein.
(ich verwende hier die Maven Version 2.0.7.)

===Beschreibung===

Schritt A: Erzeugung einer Beispiel RCP Anwendung in Eclipse:

1. File > New > Project > Plug-in

2. Project name = com.breskeby.tutorial.rcp.withMaven

3. Bei “Use default location” haken raus

4. Bei Location “-workspace-/plugins/com.breskeby.tutorial.rcp.withMaven” eintragen

5. src = src/java/main (maven konvention)

6. bin = target/classes

7. -next-

8. Haken bei “Generate Activator” und bei “this plugin contributes to the ui” setzen

9. “Would you like to create RCP Application” auf yes! -next-

10. Als template “Hello RCP” und -Finish-

Nachdem der Wizard die Applikation erzeugt hat, findet man im Formular der plugin.xml unter dem Menüpunkt Testing den Eintrag “Launch an Eclipse Application”, mit dem die Applikation testweise gestartet werden kann.

Schritt B: Erzeugung der *.product Datei:

1. File > New > Product Configuration

2. als “parent folder” sollte “com.breskeby.tutorials.rcp.withMaven” schon selektiert sein

3. file name: withmaven.product

4. product name: “RCP With Maven Example”

5. product id > New > (the default settings are okay)

6. application = com.breskeby.tutorial.rcp.withMaven.application

7. -finish-

8. Im Editor der product Datei muss Unter Configuration > Add… noch das plugin “com.breskeby.tutorial.rcp.withMaven” und
danach durch “Add Required Plug-ins” die restlichen notwendigen Plugins hinzugefügt werden

Jetzt kann die Applikation auch über das Product file gestartet werden.

Was benötigt jedes Maven Projekt und deshalb natürlich auch unsere RCP Anwendung? … Richtig, das pom.xml file!

Schritt C: pom.xml erstellen

1. File > New > File > “pom.xml” erstellen

2. copy&paste:

[source:xml] 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">
4.0.0
com.breskeby.tutorials.rcp
withmaven

zip RCP With Maven Example
1.0-SNAPSHOT
A Simple Product PDE Example

org.codehaus.mojo
pde-maven-plugin
true

C:\Programme\eclipse_rcp\eclipse\

withmaven.product 3.3.0.v20070612
[/source]

3. im Beispiel für das pom.xml muss noch der Pfad der Eclipse Installation, sowie die pdeBuildVersion richtig gesetzt werden. die findet man im Namen des
plugins “org.eclipse.pde.build” (z.B. org.eclipse.pde.build_3.3.0.v20070612 >> 3.3.0.v20070612)

Das pde-maven-plugin ist sozusagen ein wrapper um die ant tasks, die eclipse von haus aus für die “headless build automation” mitbringt. Dafür benötigen wir eine build.properties Datei, die im Verzeichnis “buildConfiguration” im ProjektOrdner abgelegt werden muss.

Schritt D. build.properties erstellen.

1. Verzeichnis buildConfiguration im Projektverzeichnis erstellen.

2. Template für die build.properties Datei (im plugin “org.eclipse.pde.build” unter templates/headless-build/build.properties) in das Verzeichnis buildConfiguration kopieren

3. In der build.propertes Datei müssen noch einige properties gesetzt:

- product ( = withmaven.product)
- base (z.B. C:/Programme/eclipse_rcp) !!Achtung: Hier Slashs und nicht Backslashs benutzen.
- baseLocation (= ${base}/eclipse)
- pluginPath ( = .)
- configs =(win32, win32, x86) !!Achtung: pde-maven-plugin unterstützt zur Zeit nur die Generierung für eine Zielplattform
- archivePrefix (= withMaven)

Eigentlich sind wir jetzt (schon) fertig. Nun kann über die Kommandozeile einfach “mvn install” aufgerufen werden. Daraufhin findet man in seinem maven repository unter com\breskeby\tutorials\rcp\withmaven\1.0-SNAPSHOT
die gezippte applikation. Einfach entzippen, starten, fertig!

===Links===
DeltaPack 3.3
Eclipse 3.3 for RCP
pde-maven-plugin
[tags]eclipse, java, rcp, maven, tutorial, howto[/tags]

15 Responses to “Tutorial: Eclipse RCPs mit Maven”

  1. Mustapha Says:
    September 18th, 2007 at 03:22

    Thanks for the tutorial. I followed all the instructions. It works all nearly good. By mvn -install I got a build error, so I tried with mvn -e install and it worked. The problem I don´t find the 1.0-SNAPSHOT !! sorry I´m new to maven, so I´m still learning. I also have a little question, why create a “New > Project > Plug-in” ? why not “New > Project > Java Project” or maybe “New > Project > Maven Project” ?

    thanks in advance

  2. Administrator Says:
    September 23rd, 2007 at 18:33

    you find the 1.0-SNAPSHOT of your application / plugin in your local maven repository. the local maven repository you find in your user directory (normally ~/.m2/repository/… )

    regards
    brs

  3. Andreas Says:
    September 26th, 2007 at 15:46

    Thanks form the introduction but i don’t put it to work for me. I use also eclipse 3.3.
    I got the following error:
    [ERROR] BUILD ERROR
    [INFO] ————————————————————————
    [INFO] C:\Programme\eclipse\startup.jar not found. Have you set up your -DeclipseInstall?

    So the path is correct but ther is no startup.jar. After googleing a little bit i found:
    http://eclipsenuggets.blogspot.com/2007/04/starting-eclipse-3.html

    Where could i found the startup.jar? or can i go around it?

  4. Andreas Says:
    September 26th, 2007 at 16:37

    Ok i found it. It is fixed in a newer SNAPSHOT version and as i corrected it (added the snapshot repo to maven) it was gracefully running.

  5. Administrator Says:
    September 29th, 2007 at 17:48

    yes i forgot to mention the missing startup.jar in the 3.3 europe distribution of eclipse. thank you andreas for raising this issue here.

    regards,
    rene

  6. Thomas Says:
    October 16th, 2007 at 15:20

    Hello, how can i get the new snapshot for eclipse 3.3?

  7. breskeby Says:
    October 18th, 2007 at 23:05

    which snapshot do you mean? a maven snapshot of the eclipse 3.3 ide? isn’t necessary here.

  8. breskeby Says:
    October 18th, 2007 at 23:08

    @thomas: if you mean the pde maven plugin, look here: pde-maven-plugin
    regards rené

  9. Michal Says:
    October 31st, 2007 at 11:15

    What about external dependencies? What if a plugin or RCP application depends on say the Eclipse Communication Framework, or another plugin? How’s this handled by maven builds?

  10. Administrator Says:
    October 31st, 2007 at 11:51

    @michal: the mojo plugin just wraps the normal capabilities of eclipse rcp developement for building a rcp application using the product config file. I found no out of the box solution for the transitive dependency management maven. I guess installing your plugins manually to your local repository and declaring dependencies to it in your pom.xml may helps you at compile time. but at packaging the rcp app, you still have problems. read the howto of building rcp with the product file: howto

    regards,
    rené

  11. Immo Hüneke Says:
    January 31st, 2008 at 13:37

    Hi René, this is an excellent tutorial. Much easier to follow than the Codehaus one. I have referenced it from my blog at http://aspsp.blogspot.com/ and if you have no objection, I’ll paraphrase it into English with the things I learned while trying to implement such a build in Eclipse RCP Developer 3.3.1.1.

    Your example POM is very well, except for the fact that tags like groupId and artifactId have been lowercased. Once I fixed those, the Maven build started up OK :-)

    One problem I am currently wrestling with is this. When I try to run a simple Maven command, such as mvn test, the build fails with:

    [INFO] Failed to resolve artifact.

    Couldn’t find a version in [3.3.0-v20070604, 3.3.0-v20070530] to match range [3.3.0,4.0.0)
    org.eclipse.core:resources:jar:null

    Looking in the target installation directory, the only relevant plugin that I have is org.eclipse.core.resources.win32_3.3.0.v20070226.jar – the other two must have been deployed earlier in our project repository as a result of running mvn eclipse:to-maven against the Eclipse RCP Developer installation.

    There isn’t even any indication of which Eclipse plugin has the dependency. Any suggestion how to overcome this?

  12. breskeby Says:
    February 4th, 2008 at 15:00

    thank you Immo for your comment. I was tired of the tutorials which just work ’til the second step or maybe til the third. When I have more time i’ll try to reconstruct the problem you posted.

    bye rené

  13. breskeby Says:
    February 4th, 2008 at 17:41

    btw.: also thanks for your reference.

  14. Administrator Says:
    February 17th, 2009 at 21:31

    the old link to this blog post works again (http://www.breskeby.com/240). even fixed that.

  15. daniel Says:
    March 17th, 2010 at 16:03

    Hi
    good tutorial.but…..

    I got the errors when I run “mvn install”

    D:\plugins\com.breskeby.tutorial.rcp.withMaven>set MAVEN_OPTS= -XX:PermSize=128M
    -XX:MaxPermSize=256M
    [INFO] Scanning for projects…
    [INFO] ————————————————————————
    [INFO] Building RCP With Maven Example
    [INFO] task-segment: [install]
    [INFO] ————————————————————————
    [INFO] [pde:ext {execution: default-ext}]
    [INFO] ————————————————————————
    [ERROR] BUILD ERROR
    [INFO] ————————————————————————
    [INFO] D:\RCPEclipse\eclipse\startup.jar not found. Have you set up your -Decli
    pseInstall?
    [INFO] ————————————————————————
    [INFO] For more information, run Maven with the -e switch
    [INFO] ————————————————————————
    [INFO] Total time: 1 second
    [INFO] Finished at: Wed Mar 17 22:56:54 CST 2010
    [INFO] Final Memory: 5M/15M
    [INFO] ————————————————————————
    I can’t fix this error using Andreas “newer SNAPSHOT “,what happened?

Comments