How do you build an SWT application with Maven
Asked Answered
V

6

25

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

Valida answered 15/11, 2008 at 13:43 Comment(1)
Quick: maven repo github.com/maven-eclipse/maven-eclipse.github.io -- since 2014. googlecode is dead.Studio
O
9

Sounds like Maven is pulling in an old version of SWT. As of v3.4 (and higher), the swt.jar is all you need. SWT will automatically extract the .sos, .jnilibs or .dlls as necessary. The only tricky thing you need to worry about is to ensure that you get the right swt.jar (meaning for your platform).

Try installing SWT 3.4 in your local repository by hand. If that still gives you the same problem, then something is probably fishy. After that, I would try extracting the .sos manually and then specifying the java.library.path variable using the -D switch on invocation. Sometimes on Linux the loading of the libraries can fail due to dependency problems (in things like libpango). In such cases, often the error will be just the generic UnsatisifedLinkError, making the problem difficult to debug.

Osterhus answered 15/11, 2008 at 17:37 Comment(0)
W
19

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!

Warram answered 2/4, 2012 at 23:32 Comment(3)
As for the dying google code service: have a look at this updated answer: #5096799Semination
maven repo github.com/maven-eclipse/maven-eclipse.github.io -- since 2014.Studio
SWT is now published on Maven Central. See this anwser: https://mcmap.net/q/529608/-how-do-you-build-an-swt-application-with-mavenSweeting
O
9

Sounds like Maven is pulling in an old version of SWT. As of v3.4 (and higher), the swt.jar is all you need. SWT will automatically extract the .sos, .jnilibs or .dlls as necessary. The only tricky thing you need to worry about is to ensure that you get the right swt.jar (meaning for your platform).

Try installing SWT 3.4 in your local repository by hand. If that still gives you the same problem, then something is probably fishy. After that, I would try extracting the .sos manually and then specifying the java.library.path variable using the -D switch on invocation. Sometimes on Linux the loading of the libraries can fail due to dependency problems (in things like libpango). In such cases, often the error will be just the generic UnsatisifedLinkError, making the problem difficult to debug.

Osterhus answered 15/11, 2008 at 17:37 Comment(0)
S
7

Since 2013 (this post inception year), things has changed. SWT is now published on Maven Central. Here are the coordinates as of this writing:

<dependency>
    <groupId>org.eclipse.platform</groupId>
    <artifactId>org.eclipse.swt.win32.win32.x86_64</artifactId>
    <version>${swt.version}</version>
</dependency>

You may find this ticket interesting.

Latest SWT artefacts for windows 64bit: https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.swt.win32.win32.x86_64

Sweeting answered 18/3, 2013 at 21:27 Comment(0)
S
3

I used github with latest Eclipse's stuff: https://github.com/maven-eclipse/maven-eclipse.github.io . I suggest you read that.

The pom.xml that worked for me:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.whatever</groupId>
  <artifactId>whatever</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>swt</name>
  <url>http://maven.apache.org</url>

    <repositories>
        <repository>
            <id>maven-eclipse-repo</id>
            <url>http://maven-eclipse.github.io/maven</url>
        </repository>
    </repositories>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <swt.version>4.6</swt.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
        <!-- select prefered one, or move the preferred on to the top: -->
        <dependency>
            <groupId>org.eclipse.swt</groupId>
            <artifactId>org.eclipse.swt.win32.win32.x86_64</artifactId>
            <version>${swt.version}</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.swt</groupId>
            <artifactId>org.eclipse.swt.win32.win32.x86</artifactId>
            <version>${swt.version}</version>
            <!-- To use the debug jar, add this -->
            <classifier>debug</classifier>
        </dependency>       
        <dependency>
            <groupId>org.eclipse.swt</groupId>
            <artifactId>org.eclipse.swt.gtk.linux.x86</artifactId>
            <version>${swt.version}</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.swt</groupId>
            <artifactId>org.eclipse.swt.gtk.linux.x86_64</artifactId>
            <version>${swt.version}</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.swt</groupId>
            <artifactId>org.eclipse.swt.cocoa.macosx.x86_64</artifactId>
            <version>${swt.version}</version>
        </dependency>

  </dependencies>
</project>
Scrivings answered 5/4, 2017 at 15:38 Comment(0)
T
2

From the API of UnsatisfiedLinkError

Thrown if the Java Virtual Machine cannot find an appropriate native-language definition of a method declared native.

I haven't tried it myself, but I think you not only need to download the main SWT jar, but a supporting 'native' JAR for your platform. For example swt-linux-gtk if you're on Linux?

Topeka answered 15/11, 2008 at 17:28 Comment(0)
V
1

I did a little more research on this and found that the swt jar is in a couple different places in the maven repository. I was using jars put out by the swt group, but after looking around a bit, I found the jars put out by the org.eclipse.swt.gtk.linux group for linux (org.eclipse.swt.win32.win32 for Windows). This is for the 3.3 version of swt. Still looking for 3.4.

Valida answered 20/11, 2008 at 1:56 Comment(3)
If this can help someone, I have started deploying SWT artifacts on my public repository: maven.ju-n.net/maven2/org/swtCheryle
No, they are not. By the way, my repo URL has changed: maven.ju-n.net/publicCheryle
See my answer below for an up-to-date repository with SWT 3.7.2 artifactsWarram

© 2022 - 2024 — McMap. All rights reserved.