Tutorial :Usage of Maven tycho-p2-plugin with SWT



Question:

How do I build an SWT application using the Eclipse P2 repository and the Maven tycho-p2-plugin?


Solution:1

You can define the target environments for 'target-platform-configuration' plugin. Whatever you are building RCP or features for multiple environments, you can let your feature to include the fragments of swt 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"/>  


Solution:2

I found the problem. Background: I'm building the editor plugin which Xtext generates for DSLs.

The plugin depends on org.eclipse.swt;version=3.7.0. The packaging is eclipse-plugin. I'm listing all the necessary environments in my parent POM.

The p2 repository is a local mirror on my hard disk which I fill by exporting a Target Definition (*.target file).

The problem is that exporting a Target Definition will create something that looks a lot like a p2 repo but there are subtle differences.

For example, you have to define a target environment (Linux/Windows/Mac, x86/x86_64, win32/cocoa/gtk) in the Target Definition file. If you don't specify anything, Eclipse will use the current platform. If you use "*", all SWT fragments will be omitted.

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

This is not enough for Tycho.

Solution: Create a proper p2 repo using this small 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 of a working Eclipse installation.


Solution:3

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

However, if you do not need to build some plugins or a RCP application, I think you do not need tycho: you just can import SWT as a normal maven dependency and build your app that way...


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »