Using SWT and JFace with Maven in non-OSGi projects

There is no problem in using SWT and JFace in Eclipse applications.
These libraries were designed for it. Eclipse building solutions handle them well (p2, Tycho…).

SWT and JFace can also be used outside Eclipse.
However, they are not usable as libraries with Maven. Only as bundles with Tycho. This is because Eclipse releases are not hosted on Maven repositories but on p2 repositories. The Maven plugin called Tycho allows Maven, among other things, to rely on p2 repositories. But it is intended to build OSGi applications.

Hopefully, there is now a regular Maven repository that hosts SWT and JFace bundles as libraries.
Thus, they can be used with Maven, in non-Osgi projects. This repository is available at this address: http://swt-repo.googlecode.com/svn/repo/

To use these libraries in a non-Osgi project, add the repository to your POM.

<repositories>
   <repository>
      <id>swt-repo</id>
      <url>https://swt-repo.googlecode.com/svn/repo/</url>
   </repository>
</repositories>

If you only want to use SWT, add the SWT library that fits your operating system.
As an example, for Windows x64.

<dependencies>
   <!-- SWT -->
   <dependency>
      <groupId>org.eclipse.swt</groupId>
      <artifactId>org.eclipse.swt.win32.win32.x86_64</artifactId>
      <version>3.7.2</version>
   </dependency>
</dependencies>

If in addition you want to use JFace and Eclipse extensions for JFace (ListDialog, ListeSelectionDialog…), add the following dependency. This will add JFace by transitivity.

<dependencies>
   <!-- JFace + Eclipse's JFace extensions -->
   <dependency>
      <groupId>org.eclipse.ui</groupId>
      <artifactId>org.eclipse.ui.workbench</artifactId>
      <version>3.7.1.v20120104-1859</version>
   </dependency>
</dependencies>

If you need JFace but not its Eclipse extensions, add instead…

<dependencies>
   <!-- JFace dependencies -->
   <dependency>
      <groupId>org.eclipse.jface</groupId>
      <artifactId>org.eclipse.jface</artifactId>
      <version>3.7.0.v20110928-1505</version>
   </dependency>
</dependencies>

Other versions of SWT and JFace should be added to the repository.
Another solution could be based on Tycho. But so far, I have not found any solution. I started a thread about this on the Tycho-user mailing list.

Anyway, the solution described above will fit all the Maven versions.
A Tycho-based solution would only work with Maven3 (but would avoid duplicating the libraries).

9 thoughts on “Using SWT and JFace with Maven in non-OSGi projects

      1. Hi,

        You are right. In fact, swt-repo was created because there is no official support of Maven with SWT (except through Tycho when developping for Eclipse). You can find more information and all the related history in this bug at Eclipse.org.

  1. I want just to add that if you need to setup dependecies in maven for different OS you can use “profiles” like this:

    swt-linux

    unix

    org.eclipse.swt
    org.eclipse.swt.gtk.linux.x86
    3.7.2

    swt-win

    windows

    org.eclipse.swt
    org.eclipse.swt.win32.win32.x86
    3.7.2

    Thanks for this post!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s