题
我尝试学习 swt,我使用 maven 进行所有构建,使用 eclipse 进行 IDE。当从 Maven 存储库中获取 swt jar 时,我得到:
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)
有没有人成功地使用 Maven 构建和运行 swt 应用程序?
编辑: :我做了一些研究并发现了问题。看我下面的帖子
解决方案
听起来Maven正在推出一个旧版本的SWT。从v3.4(及更高版本)开始,swt.jar就是你需要的所有。 SWT将根据需要自动提取.so
s,.jnilib
s或.dll
。您需要担心的唯一棘手的事情是确保您获得正确的swt.jar(意味着您的平台)。
尝试手动在本地存储库中安装SWT 3.4。如果这仍然给你带来同样的问题,那么事情可能是多么可疑。之后,我会尝试手动提取java.library.path
,然后使用-D
开启调用指定UnsatisifedLinkError
变量。有时在Linux上,由于依赖性问题(例如libpango之类的东西),库的加载可能会失败。在这种情况下,错误通常只是通用的<=>,使问题难以调试。
其他提示
我已将最新 SWT 版本 (4.2.2) 的 win32/64 和 osx 工件上传到 googlecode 存储库,您可以在这里找到它:
https://swt-repo.googlecode.com/svn/repo/
要使用它,只需将以下内容放入 pom.xml 中:
<repositories>
<repository>
<id>swt-repo</id>
<url>https://swt-repo.googlecode.com/svn/repo/</url>
</repository>
</repositories>
然后您只需引用与您的平台相关的 SWT 依赖项即可。例如:
<dependency>
<groupId>org.eclipse.swt</groupId>
<artifactId>org.eclipse.swt.win32.win32.x86</artifactId>
<version>4.2.2</version>
</dependency>
对于其他平台,只需将artifactId替换为适当的值:
- 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
还提供其他平台和旧版本的工件,请访问上面的存储库链接来查找它们。
快乐编码!
来自 UnsatisfiedLinkError 的API
如果Java虚拟机无法找到声明为native的方法的适当本机语言定义,则抛出该文件。
我自己没有尝试过,但我认为你不仅需要下载主要的SWT jar,而且需要为你的平台下载支持“原生”的JAR。例如swt-linux-gtk如果你在Linux上?
我使用github和最新的Eclipse东西: https://github.com/maven-eclipse/maven-eclipse.github。 io 。我建议你阅读。
对我有用的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>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>
我对此进行了一些研究,发现swt jar位于maven存储库中的几个不同位置。我正在使用swt小组推出的罐子,但是在看了一下之后,我发现了org.eclipse.swt.gtk.linux组为linux发布的jar(org.eclipse.swt.win32.win32 for Windows) )。这是针对swt的3.3版本。仍在寻找3.4。
自2013年(本年度开始)以来,情况发生了变化。 SWT现在发布在Maven Central上。 以下是撰写本文时的坐标:
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.swt.win32.win32.x86_64</artifactId>
<version>${swt.version}</version>
</dependency>
您可能会发现此彩票很有趣。
适用于Windows 64位的最新SWT文物: https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.swt.win32.win32.x86_64