Deploying SWT applications for different platforms

It’s been a while since my last blog post but here’s a quick ‘lessons learned’.

Maybe I am the only one being not smart enough to know the solution to the following issue instantly but if you’re currently developing a SWT based Java application on one platform and struggling to get it going on another platform, here’s some advice.

Problems: My SWT application was build on a Mac running Eclipse 3.7. The goal was to see the application running on a PC laptop. Two issues came across while trying to achieve this. The first one being the fact that SWT applications built on 64-bit system will not work on a 32-bit system and vice versa. You will get one of the following error messages “Exception in thread “main”  java.lang.UnsatisfiedLinkError: Cannot  load 32-bit SW T libraries on 64-bit  JVM.” or “Exception in thread “main”  java.lang.UnsatisfiedLinkError: Cannot  load 64-bit SW T libraries on 32-bit  JVM.“. The second error will occur due to the fact that on the developing machine the library of the target system wasn’t referenced in the build path properly. The error message may look like this “Exception in thread “main”  java.lang.UnsatisfiedLinkError: Could not load SWT library. Reasons: no swt-cocoa-3740 in java.library.path.“.

How to fix this

Preparing for 32Bit: To work around the 32/64 bit issue you need to target the appropriate JVM. If you’re developing on 64bit machine and want to deploy the application for a 32bit system then you can simply add a parameter to your JRE preferences; the 32bit JVM should be installed already. Go to Window > Preferences > Java > Installed JREs. Select the JRE, click Edit, find the Default VM Arguments field and enter the parameter “-d32“. This will force Eclipse to use the 32Bit JVM on running the project or creating an executable jar.

Switching libraries: Although it is said to be a cross-platform development you will still need different libraries for different platforms. Make sure that you have the appropriate SWT library for your target system (you can find them on and add the libraries to the Build Path. If you’re running the project on your developing machine it will probably choose the correct library automatically. However you can pinpoint the correct library (i.e. for deploying to other machines) by simply removing all unnecessary libraries from the Build Path.

All in all this solution isn’t the most pretty one but it worked fine for me and allows for quick changes during development.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s