开发者

SWT + Maven + Eclipse = java.lang.UnsatisfiedLinkError: no swt-carbon-3346 or swt-carbon in swt.library.path

开发者 https://www.devze.com 2023-03-15 13:10 出处:网络
I am trying to get a hello world SWT application going: public static void main(String args[]) throws IOException{

I am trying to get a hello world SWT application going:

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. 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. Loading JNI libraries is a little bit different than normal classloading (the dynamic libraries must first be loaded with System#loadLibrary).

First, if you're on a 64 bit machine, make sure that you're passing the -d32 argument to the JRE. (ie, java -d32 MyTestClass). The Carbon SWT libraries are 32 bit only and will not load on a 64 bit runtime.

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 will try to unzip this jnilib from your JAR into a temporary location and load that.

If it can't do this for whatever reason (java.io.tmpdir isn't writable, for example) then this will fail. 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. (For example, set swt.library.path to the location of that jnilib.)

Unrelated to your actual question: you're using SWT 3.3. A lot of changes have been made since then, including the (likely preferable) Cocoa support. Upgrading to the newest SWT libraries in the newest Eclipse may be very helpful.

0

精彩评论

暂无评论...
验证码 换一张
取 消