24

我试图学习 swt,我在所有构建中使用 maven,在我的 IDE 中使用 eclipse。从 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 应用程序?

编辑:我做了一些研究,发现了问题。看看我下面的帖子

4

6 回答 6

19

我已将最新 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

其他平台和旧版本的工件也可用,请访问上面的存储库链接以找到它们。

快乐编码!

于 2012-04-02T23:32:42.100 回答
9

听起来 Maven 正在引入旧版本的 SWT。从 v3.4(及更高版本)开始,您只需要swt.jar 。SWT 将根据需要自动提取.sos、.jnilibs 或.dlls。您需要担心的唯一棘手的事情是确保您获得正确的 swt.jar(对您的平台有意义)。

尝试在本地存储库中手动安装 SWT 3.4。如果这仍然给你同样的问题,那么可能是有问题的。之后,我会尝试.so手动提取 s,然后使用调用时的开关指定java.library.path变量。-D有时在 Linux 上,由于依赖问题(例如 libpango),库的加载可能会失败。在这种情况下,错误通常只是泛型UnsatisifedLinkError,使问题难以调试。

于 2008-11-15T17:37:54.617 回答
5

自 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

于 2013-03-18T21:27:17.510 回答
2

来自UnsatisfiedLinkError的 API

如果 Java 虚拟机找不到声明为本地的方法的适当本地语言定义,则抛出此异常。

我自己没有尝试过,但我认为您不仅需要下载主要的 SWT jar,还需要为您的平台下载一个支持“本机”JAR。例如 swt-linux-gtk 如果你在 Linux 上?

于 2008-11-15T17:28:09.770 回答
2

我将 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>
于 2017-04-05T15:38:05.713 回答
1

我对此进行了更多研究,发现 swt jar 位于 maven 存储库中的几个不同位置。我使用的是 swt 组推出的 jars,但环顾四周后,我发现 org.eclipse.swt.gtk.linux 组为 linux 推出的 jars(org.eclipse.swt.win32.win32 for Windows )。这是 swt 的 3.3 版本。还在找3.4。

于 2008-11-20T01:56:19.180 回答