I have an SWT app running fine within Eclipse. Now, I want to bundle the project as a stand-alone app with Maven:
$ mvn compile assembly:single
I am using this pom.xml:
<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>pmu</groupId>
<artifactId>swtsandbox</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>swtsandbox</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<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.1</swt.version>
</properties>
<repositories>
<repository>
<id>maven-eclipse-repo</id>
<url>http://maven-eclipse.github.io/maven</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</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.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>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.2</version>
<configuration>
<!-- put your configurations here -->
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>pmu.swtsandbox.App</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
When I run the resulting jar I get:
pm:target pmu$ java -jar swtsandbox-0.0.1-SNAPSHOT-jar-with-dependencies.jar Exception in thread "main" java.lang.UnsatisfiedLinkError: Could not load SWT library. Reasons:
no swt-gtk-4626 in java.library.path
no swt-gtk in java.library.path
Can't load library: /Users/pmu/.swt/lib/macosx/x86_64/libswt-gtk-4626.jnilib
Can't load library: /Users/pmu/.swt/lib/macosx/x86_64/libswt-gtk.jnilib
at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
at org.eclipse.swt.internal.C.<clinit>(Unknown Source)
at org.eclipse.swt.internal.Converter.wcsToMbcs(Unknown Source)
at org.eclipse.swt.internal.Converter.wcsToMbcs(Unknown Source)
at org.eclipse.swt.widgets.Display.<clinit>(Unknown Source)
at pmu.swtsandbox.App.main(App.java:14)
Apparently, the Eclipse app is finding the SWT JNI libs, but they are not included in the Maven build.
When I search for the SWT libs, this gets:
/Users/pmu/eclipse/cpp-neon/Eclipse.app/Contents/Eclipse/configuration/org.eclipse.osgi/409/0/.cp/libswt-cocoa-4628.jnilib
/Users/pmu/eclipse/cpp-neon/Eclipse.app/Contents/Eclipse/configuration/org.eclipse.osgi/409/0/.cp/libswt-pi-cocoa-4628.jnilib
/Users/pmu/eclipse/cpp-neon/Eclipse.app/Contents/Eclipse/configuration/org.eclipse.osgi/58/0/.cp/os/macosx/x86_64/libpty.jnilib
/Users/pmu/eclipse/cpp-neon/Eclipse.app/Contents/Eclipse/configuration/org.eclipse.osgi/58/0/.cp/os/macosx/x86_64/libspawner.jnilib
/Users/pmu/eclipse/cpp-neon/Eclipse.app/Contents/Eclipse/configuration/org.eclipse.osgi/99/0/.cp/os/macosx/libunixfile_1_0_0.jnilib
/Users/pmu/eclipse/java-mars/Eclipse.app/Contents/Eclipse/configuration/org.eclipse.osgi/387/0/.cp/libswt-cocoa-4530.jnilib
/Users/pmu/eclipse/java-mars/Eclipse.app/Contents/Eclipse/configuration/org.eclipse.osgi/387/0/.cp/libswt-pi-cocoa-4530.jnilib
/Users/pmu/eclipse/java-mars/Eclipse.app/Contents/Eclipse/configuration/org.eclipse.osgi/79/0/.cp/os/macosx/libunixfile_1_0_0.jnilib
/Users/pmu/eclipse/java-neon/Eclipse.app/Contents/Eclipse/configuration/org.eclipse.osgi/389/0/.cp/libswt-cocoa-4628.jnilib
/Users/pmu/eclipse/java-neon/Eclipse.app/Contents/Eclipse/configuration/org.eclipse.osgi/389/0/.cp/libswt-pi-cocoa-4628.jnilib
/Users/pmu/eclipse/java-neon/Eclipse.app/Contents/Eclipse/configuration/org.eclipse.osgi/79/0/.cp/os/macosx/libunixfile_1_0_0.jnilib