SWT for different platforms

I am using JWebBrowser in a swing application. This class is owned by DJ Project . To execute, you need to use the jar swt. Now I have included the swt jar for windows in my package with the application ATM. I want to know how to enable swt boxes for linux / mac in one package? I am using ant to build a jar application. Should I build a can by putting a different can for a different platform?

+6
source share
3 answers

if you want to have one assembly that runs on different platforms (Win / Mac / Linux / * nix) or architectures (32/64 bit), then you can link the SWT bank for each target platform with your installer, and then load the correct one dynamically at runtime (or your installer will copy the correct SWT jar during installation).

eg. let's say you want to support 32-bit and 64-bit Windows and Linux, you will have SWT banks:

lib/swt_win_32.jar lib/swt_win_64.jar lib/swt_linux_32.jar lib/swt_linux_32.jar 

Make your ant script / installer all included (about 1.6 MB each), and then during code execution you can discover the OS and architecture using the properties of the Java system.

 System.getProperty("os.name"); System.getProperty("os.arch"); 

to create the name of the correct jar file.

Loading a flag at runtime can be done by a custom class loader or by calling the protected method URLClassloader.addURL(URL url) using reflection.

I put the working code to perform this exact task on my website: http://www.chrisnewland.com/select-correct-swt-jar-for-your-os-and-jvm-at-runtime-191

If you can handle the smell of code, then this is a quick fix to a very common SWT problem.

+9
source

On Mac OS + X, you can include the required JAR and JNI libraries in the application package , as shown in this . See Also Deploying SWT Applications on Mac OS X.

On Linux, most platforms provide the swt-gtk package. As a concrete example, here's a script run for AppleCommander :

 java -Djava.library.path=/usr/lib/jni \ -cp /usr/lib/java/swt-gtk-3.5.1.jar:AppleCommander-1.3.5.8.jar \ com.webcodepro.applecommander.ui.AppleCommander -swt 
+2
source

This answer contains code for choosing the right SWT JAR when starting the application: Creating a cross-platform Java SWT application

All you have to do is put all the JARs in the correct folder and the code will pick them up.

+1
source

Source: https://habr.com/ru/post/895501/


All Articles