如何使用Maven构建SWT应用程序

时间:2022-05-10 22:22:57

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:

我尝试学习swt,并为我的IDE使用maven来构建所有的构建和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)

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

有人成功地使用maven构建和运行swt应用程序吗?

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

编辑:我做了一些调查,发现了问题所在。看看我下面的帖子

6 个解决方案

#1


10  

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).

听起来好像Maven正在引入一个旧版本的SWT。当v3.4(或更高)时,swt。你只需要jar。SWT将根据需要自动提取.sos、.jnilibs或.dll。你需要担心的唯一棘手的事情是确保你得到了正确的swt。jar(指你的平台)。

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.

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

#2


17  

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:

我已经上传了最新SWT版本(4.2.2)的win32/64 & osx工件到googlecode存储库,您可以在这里找到:

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

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

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

要使用它,只需在您的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:

然后您可以引用与平台相关的SWT依赖项。例如:

    <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:

对于其他平台,只需用适当的值替换artifactId:

  • org.eclipse.swt.win32.win32.x86
  • org.eclipse.swt.win32.win32.x86
  • org.eclipse.swt.win32.win32.x86_64
  • org.eclipse.swt.win32.win32.x86_64
  • org.eclipse.swt.cocoa.macosx
  • org.eclipse.swt.cocoa.macosx
  • org.eclipse.swt.cocoa.macosx.x86_64
  • 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.

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

Happy coding!

编码快乐!

#3


2  

From the API of UnsatisfiedLinkError

来自UnsatisfiedLinkError的API

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

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

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?

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

#4


2  

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

我使用github访问最新的Eclipse: https://github.com/maven-eclipse/maven-eclipse.githuio。我建议你读一下。

The pom.xml that worked for me:

砰的一声。对我有用的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>

#5


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.

我对此做了一些研究,发现swt jar位于maven存储库中的几个不同位置。我使用的是swt组发出的jar,但是在环顾一下之后,我发现了org. eclipsee .swt.gtk发出的jar。linux linux的linux组(org.eclipse.swt.win32)。win32 Windows)。这是针对3.3版swt的。3.4还在寻找。

#6


1  

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

自2013年(今年是《盗梦空间》上映的一年)以来,情况发生了变化。SWT现在发布在Maven中心上。以下是这篇文章的坐标:

<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

windows64位的最新SWT artefacts: https://mvnrepository.com/artifact/org.eclipse.platform/org.org.eclipse.swt.win32 .win32.x86_64

#1


10  

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).

听起来好像Maven正在引入一个旧版本的SWT。当v3.4(或更高)时,swt。你只需要jar。SWT将根据需要自动提取.sos、.jnilibs或.dll。你需要担心的唯一棘手的事情是确保你得到了正确的swt。jar(指你的平台)。

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.

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

#2


17  

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:

我已经上传了最新SWT版本(4.2.2)的win32/64 & osx工件到googlecode存储库,您可以在这里找到:

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

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

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

要使用它,只需在您的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:

然后您可以引用与平台相关的SWT依赖项。例如:

    <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:

对于其他平台,只需用适当的值替换artifactId:

  • org.eclipse.swt.win32.win32.x86
  • org.eclipse.swt.win32.win32.x86
  • org.eclipse.swt.win32.win32.x86_64
  • org.eclipse.swt.win32.win32.x86_64
  • org.eclipse.swt.cocoa.macosx
  • org.eclipse.swt.cocoa.macosx
  • org.eclipse.swt.cocoa.macosx.x86_64
  • 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.

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

Happy coding!

编码快乐!

#3


2  

From the API of UnsatisfiedLinkError

来自UnsatisfiedLinkError的API

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

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

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?

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

#4


2  

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

我使用github访问最新的Eclipse: https://github.com/maven-eclipse/maven-eclipse.githuio。我建议你读一下。

The pom.xml that worked for me:

砰的一声。对我有用的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>

#5


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.

我对此做了一些研究,发现swt jar位于maven存储库中的几个不同位置。我使用的是swt组发出的jar,但是在环顾一下之后,我发现了org. eclipsee .swt.gtk发出的jar。linux linux的linux组(org.eclipse.swt.win32)。win32 Windows)。这是针对3.3版swt的。3.4还在寻找。

#6


1  

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

自2013年(今年是《盗梦空间》上映的一年)以来,情况发生了变化。SWT现在发布在Maven中心上。以下是这篇文章的坐标:

<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

windows64位的最新SWT artefacts: https://mvnrepository.com/artifact/org.eclipse.platform/org.org.eclipse.swt.win32 .win32.x86_64