Eclipse: export project such that Windows and Mac can both run it (SWT)
  TnD0WQEygW8e 2023年11月14日 52 0

 [root@localhost aimin]# java -jar TASTS.jar
Exception in thread "main" java.lang.UnsatisfiedLinkError: Could not load SWT library. Reasons:
    no swt-win32-4930r7 in java.library.path
    no swt-win32 in java.library.path
    Can't load library: /root/.swt/lib/linux/x86_64/libswt-win32-4930r7.so
    Can't load library: /root/.swt/lib/linux/x86_64/libswt-win32.so

    at org.eclipse.swt.internal.Library.loadLibrary(Library.java:344)
    at org.eclipse.swt.internal.Library.loadLibrary(Library.java:256)
    at org.eclipse.swt.internal.C.<clinit>(C.java:19)
    at org.eclipse.swt.widgets.Display.<clinit>(Display.java:145)
    at MainForm.main(MainForm.java:10)
[root@localhost aimin]#
--------------------

[root@localhost aimin]# java -jar TASTS-linux64.jar
Exception in thread "main" java.lang.UnsatisfiedLinkError: Could not load SWT library. Reasons:
    no swt-pi4-gtk-4934r6 in java.library.path
    no swt-pi4-gtk in java.library.path
    Can't load library: /root/.swt/lib/linux/x86_64/libswt-pi4-gtk-4934r6.so
    Can't load library: /root/.swt/lib/linux/x86_64/libswt-pi4-gtk.so

    at org.eclipse.swt.internal.Library.loadLibrary(Library.java:342)
    at org.eclipse.swt.internal.Library.loadLibrary(Library.java:256)
    at org.eclipse.swt.internal.gtk.OS.<clinit>(OS.java:90)
    at org.eclipse.swt.internal.Converter.wcsToMbcs(Converter.java:209)
    at org.eclipse.swt.internal.Converter.wcsToMbcs(Converter.java:155)
    at org.eclipse.swt.widgets.Display.<clinit>(Display.java:164)
    at MainForm.main(MainForm.java:10)
-----------------------

[root@localhost aimin]# ls /root/.swt/lib/linux/x86_64/
libswt-gtk-4934r6.so  libswt-pi3-gtk-4934r6.so

---------------

You appear to be running a SWT application. On macOS you must specify the -XstartOnFirstThread option when running the jar to run SWT correctly:

jar -XstartOnFirstThread -jar xxxx.jar

SWT applications also have a native library which is different for each platform.

---------------

You have to add the correct SWT.jar to the classpath. You can download them here. (https://www.eclipse.org/swt/)

If you are deploying for Windows, you will have to bundle the swt jar for Windows (either 32bit or 64bit depending on the system).

If you want to create an application that runs on all platforms, have a look at this post:

Create cross platform Java SWT Application (https://stackoverflow.com/questions/2706222/create-cross-platform-java-swt-application/3204032#3204032)

---------------

 

REF

https://stackoverflow.com/questions/2706222/create-cross-platform-java-swt-application/3204032#3204032

https://stackoverflow.com/questions/16567936/swt-running-an-application-developed-on-osx-in-windows

https://stackoverflow.com/questions/42777000/eclipse-export-project-such-that-windows-and-mac-can-both-run-it

 https://stackoverflow.com/questions/3959556/problems-with-loading-resources-during-execution

http://mchr3k.github.io/swtjar/

 



【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月14日 0

暂无评论

推荐阅读
TnD0WQEygW8e