Using Maven tycho-p2-plugin with SWT

How to create a SWT application using the Eclipse P2 repository and Maven tycho-p2-plugin?

+6
java maven swt p2 tycho
source share
3 answers

You can define target environments for the target-platform-configuration plugin. Regardless of the fact that you create RCP or functions for several environments, you can let your function include swt fragments for these hosts.

<plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>target-platform-configuration</artifactId> <version>${tycho-version}</version> <configuration> <resolver>p2</resolver> <environments> <environment> <os>linux</os> <ws>gtk</ws> <arch>x86</arch> </environment> <environment> <os>win32</os> <ws>win32</ws> <arch>x86</arch> </environment> <environment> <os>solaris</os> <ws>gtk</ws> <arch>sparc</arch> </environment> </environments> </configuration> </plugin> 

Snippet in feature.xml

  <plugin id="org.eclipse.swt" download-size="0" install-size="0" version="0.0.0" unpack="false"/> <plugin id="org.eclipse.swt.gtk.linux.x86" os="linux" ws="gtk" arch="x86" download-size="0" install-size="0" version="0.0.0" fragment="true" unpack="false"/> <plugin id="org.eclipse.swt.win32.win32.x86" os="win32" ws="win32" arch="x86" download-size="0" install-size="0" version="0.0.0" fragment="true" unpack="false"/> 
+4
source share

Tycho allows you to create and compile eclipse-based content, including RCP plugins, features, and applications. There are tons of a good tutorial on the official project page, but in my case I used a sample project ( http://git.eclipse.org/c/tycho/org.eclipse.tycho-demo.git/tree/itp04-rcp ).

However, if you do not need to create some plugins or an RCP application, I think you do not need tycho: you can just import SWT as a normal maven dependency and create the application this way ...

+2
source share

I found a problem. Prerequisites: I create an editor plugin that Xtext generates for DSL.

The plugin depends on org.eclipse.swt;version=3.7.0 . packaging - eclipse-plugin . I lists all the necessary environments in the parent POM .

The p2 repository is a local mirror on my hard drive, which I populate by exporting the target definition file (* .target).

The problem is that exporting the target definition will create something that is very similar to the p2 repository, but there are subtle differences.

For example, you must define the target environment (Linux / Windows / Mac, x86 / x86_64, win32 / cocoa / gtk) in the target definition file. If you do not specify anything, Eclipse will use the current platform. If you use "*", all SWT fragments will be omitted.

This means: the export contains all SWT fragments (30 plugins in the plugins/ folder), they are mentioned in contents.jar , but artifact.jar contains only one SWT fragment that matches your current platform (i.e. bundle plus sources) .

This is not enough for Tycho.

Decision. Create the correct p2 repo using this little script:

 # Where you exported the Target Definition dir="$HOME/3.7.1-from-target-platform" # Where the result should be written. Must be != dir dest="$HOME/3.7.1-from-target-platform-fixed" # Make sure subsequent invocations don't try to merge old stuff rm -rf "$dest" # Prepend "file:" to create a URL from the path dest="file:$dest" echo "Merging $dir..." ./eclipse -nosplash \ -application org.eclipse.equinox.p2.publisher.FeaturesAndBundlesPublisher \ -metadataRepository "$dest" \ -artifactRepository "$dest" \ -repositoryName "3.7.1 Indigo Repository" \ -source "$dir" \ -compress -append -publishArtifacts 

Run this inside your working Eclipse installation.

+2
source share

All Articles