How do you build an SWT application with Maven

Dave picture Dave · Nov 15, 2008 · Viewed 28.4k times · Source

I trying to learn swt, and I use maven for all my builds and eclipse for my IDE. When getting the swt jars out of the maven repository, I get:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no swt-pi-gtk-3034 in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1709)
    at java.lang.Runtime.loadLibrary0(Runtime.java:823)
    at java.lang.System.loadLibrary(System.java:1030)
    at org.eclipse.swt.internal.Library.loadLibrary(Library.java:100)
    at org.eclipse.swt.internal.gtk.OS.<clinit>(OS.java:19)
    at org.eclipse.swt.internal.Converter.wcsToMbcs(Converter.java:63)
    at org.eclipse.swt.internal.Converter.wcsToMbcs(Converter.java:54)
    at org.eclipse.swt.widgets.Display.<clinit>(Display.java:112)
    at wenzlick.test.swt.main.Main.main(Main.java:30)

Has anyone successfully got a swt app to build and run using maven?

Edit: I did a little research and found the problem. look at my post below

Answer

urish picture urish · Apr 3, 2012

I have uploaded the win32/64 & osx artifacts of the latest SWT version (4.2.2) to a googlecode repository, you can find it here:

https://swt-repo.googlecode.com/svn/repo/

To use it just put the following in your pom.xml:

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

Then you can just reference the SWT dependency relevant to your platform. For example:

    <dependency>
        <groupId>org.eclipse.swt</groupId>
        <artifactId>org.eclipse.swt.win32.win32.x86</artifactId>
        <version>4.2.2</version>
    </dependency>

For other platforms, just replace artifactId with the appropriate value:

  • org.eclipse.swt.win32.win32.x86
  • org.eclipse.swt.win32.win32.x86_64
  • org.eclipse.swt.cocoa.macosx
  • org.eclipse.swt.cocoa.macosx.x86_64

Artifacts for additional platforms and older versions are available as well, visit the repository link above to find them.

Happy coding!