Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm a Java newbie who just a made a simple Java program using SWT for GUI via eclipse Juno. The code was working and the program was able to run inside eclipse, so I compiled it and made it a runnable jar file so it can be run outside eclipse. I tried to run it using the terminal and this error came up.

Exception in thread "main" java.lang.UnsatisfiedLinkError: Could not load SWT library. Reasons: 
no swt-gtk-4233 in java.library.path
no swt-gtk in java.library.path
Can't load library: /home/abody/.swt/lib/linux/x86_64/libswt-gtk-4233.so
Can't load library: /home/abody/.swt/lib/linux/x86_64/libswt-gtk.so

at org.eclipse.swt.internal.Library.loadLibrary(Library.java:331)
at org.eclipse.swt.internal.Library.loadLibrary(Library.java:240)
at org.eclipse.swt.internal.C.<clinit>(C.java:21)
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:133)
at Class1.main(Class1.java:12)

So now it looks like it can't find libswt-gtk-4233.so and the other file. However, when I took a look at the .swt folder I had an libswt-gtk-3740.so not 4233.

So its trying to find a file that is more up-to-date. So what does that mean, should I update SWT? what's going on?

share|improve this question

2 Answers 2

You need to make a symbolic link to the swt so files located in the /usr/lib/jni directory. I found a solution on this site: Eclipse cannot load SWT libraries.

use this command:

ln -s /usr/lib/jni/libswt-* ~/.swt/lib/linux/x86_64/
share|improve this answer
1  
Can you improve your answer by writing the needed command line ? Thank you. –  NorTicUs Nov 21 '12 at 13:47
    
sure, :-) done. –  wolfg Dec 29 '12 at 5:15

So now it looks like it can't find libswt-gtk-4233.so and the other file. However, when I took a look at the .swt folder I had an libswt-gtk-3740.so not 4233.

The plugin itself has those libraries.

Right click in your project:
-> Properties -> Build path
Once on Java Build Path window, the Projects's tab contains org.eclipse.swt.%GUI%.%PLATFORM%
(the project you've imported)
Click to expand.
Edit Native library location.
Select workspace, then the whole project org.eclipse.swt.%GUI%.%PLATFOM%
Press Ok, and you're done!

About:

..so I compiled it and made it a runnable jar file so it can be run outside eclipse. I tried to run it using the terminal and this error came up.


I don't know how you ran in Eclipse and not in terminal. So, I thought you meant to do it on another platform. For those that are new (like me) please read the wiky: Standard Widget Toolkit

..Programs that call SWT are portable, but the implementation of the toolkit, despite part of it being written in Java, is unique for each platform...

SWT must be ported to every new GUI library that needs supporting. Unlike Swing and AWT, SWT is not available on every Java-supported platform since SWT is not part of the Java release...

Since the SWT implementation is different for each platform, a platform-specific SWT library (JAR file) must be distributed with each application.

Therefore, if you want to export your project to a specific platform, you have to open your IDE on that platform, repeat import the plugin but this time for that platform, remove from the -build path- the projects unrelated (Not delete the projects). And now, you can compile for that specific platform.

If you switch from one platform to another, as you develop into the project, just edit the build path removing unrelated projects there.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.