[英]SWT + Maven + Eclipse = java.lang.UnsatisfiedLinkError: no swt-carbon-3346 or swt-carbon in swt.library.path
I am trying to get a hello world SWT application going: 我想要一个hello world SWT应用程序:
public static void main(String args[]) throws IOException{
Display display = new Display ();
Shell shell = new Shell(display);
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
But I keep getting the following exception. 但我一直得到以下例外。 I have the macosx version of org.eclipse.swt.carbon being used with eclipse/maven.
我有与eclipse / maven一起使用的org.eclipse.swt.carbon的macosx版本。 Has anyone seen this before?
谁看过这个吗?
Exception in thread "main" java.lang.UnsatisfiedLinkError: no swt-carbon-3346 or swt-carbon in swt.library.path, java.library.path or the jar file
at org.eclipse.swt.internal.Library.loadLibrary(Library.java:219)
at org.eclipse.swt.internal.Library.loadLibrary(Library.java:151)
at org.eclipse.swt.internal.C.<clinit>(C.java:21)
at org.eclipse.swt.widgets.Display.createDisplay(Display.java:943)
at org.eclipse.swt.widgets.Display.create(Display.java:937)
at org.eclipse.swt.graphics.Device.<init>(Device.java:119)
at org.eclipse.swt.widgets.Display.<init>(Display.java:749)
at org.eclipse.swt.widgets.Display.<init>(Display.java:740)
at com.wuntee.aat.command.adb.LogCat.main(LogCat.java:30)
SWT is implemented using native UI libraries - in this case, the Mac Carbon libraries - and requires some JNI code to marshal the SWT calls to the native Carbon calls. SWT是使用本机UI库(在本例中为Mac Carbon库)实现的,并且需要一些JNI代码来编组对本机Carbon调用的SWT调用。 Loading JNI libraries is a little bit different than normal classloading (the dynamic libraries must first be loaded with
System#loadLibrary
). 加载JNI库与正常的类加载有点不同(动态库必须首先加载
System#loadLibrary
)。
First, if you're on a 64 bit machine, make sure that you're passing the -d32
argument to the JRE. 首先,如果您使用的是64位计算机,请确保将
-d32
参数传递给JRE。 (ie, java -d32 MyTestClass
). (即
java -d32 MyTestClass
)。 The Carbon SWT libraries are 32 bit only and will not load on a 64 bit runtime. Carbon SWT库仅为32位,不会在64位运行时加载。
By default, SWT tries to load the .jnilib
dynamic libraries from a JAR file in your classpath - the library libswt-carbon-3346.jnilib
should be in your org.eclipse.swt.carbon.macosx...
JAR. 默认情况下,SWT尝试从类路径中的JAR文件加载
.jnilib
动态库 - 库libswt-carbon-3346.jnilib
应该在您的org.eclipse.swt.carbon.macosx...
JAR中。 SWT will try to unzip this jnilib
from your JAR into a temporary location and load that. SWT会尝试将这个
jnilib
从您的JAR解压缩到一个临时位置并加载它。
If it can't do this for whatever reason ( java.io.tmpdir
isn't writable, for example) then this will fail. 如果由于某种原因它无法执行此操作(例如,
java.io.tmpdir
不可写),那么这将失败。 To work around this, you should extract libswt-carbon-3346.jnilib
from the org.eclipse.swt.carbon.macosx
JAR and follow the instructions that the exception provided. 要解决此问题,您应该从
org.eclipse.swt.carbon.macosx
JAR中提取libswt-carbon-3346.jnilib
,并按照提供的异常的说明进行操作。 (For example, set swt.library.path
to the location of that jnilib.) (例如,将
swt.library.path
设置swt.library.path
的位置。)
Unrelated to your actual question: you're using SWT 3.3. 与您的实际问题无关:您使用的是SWT 3.3。 A lot of changes have been made since then, including the (likely preferable) Cocoa support.
自那时以来已经做了很多改变,包括(可能更可取的)Cocoa支持。 Upgrading to the newest SWT libraries in the newest Eclipse may be very helpful.
在最新的Eclipse中升级到最新的SWT库可能会非常有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.