It is possible to extract class files that are common between all desired platforms into a separate jar. Then remove these common classes from the platform specific jars.
At runtime you add both the common jar and the platform specific jar to the URLClassLoader.
Works for me.
Here is an old shell script I used to repack the jars, I hope it works:
#!/bin/bash
ref=""
for jar in *.jar ; do
base="${jar%%.jar}"
mkdir "$base"
( cd "$base" ; unzip -o ../${jar} ;)
ref="$base"
done
mkdir common
echo "Base is ${ref}"
( cd "$ref" ; find . -type f ) | while read f ; do
fd5=`cat "${ref}/${f}" | md5sum`
echo "Processing ${f}..."
same="yes"
for jar in *.jar ; do
if [[ "x${same}" == "xyes" ]] ; then
base="${jar%%.jar}"
if [[ -f "${base}/${f}" ]] ; then
fd5b=`cat "${base}/${f}" | md5sum `
if [[ "x${fd5}" == "x${fd5b}" ]] ; then
echo " - same ${fd5} == ${fd5b} in ${base}"
else
echo " - different ${fd5} != ${fd5b} in ${base}"
same="no"
fi
else
echo " - missing in ${base}"
same="no"
fi
fi
done
if [[ "x${same}" == "xyes" ]] ; then
echo " - IDENTICAL"
d=`dirname "${f}"`
mkdir -p "common/${d}"
cp "${ref}/${f}" "common/${f}"
for jar in *.jar ; do
base="${jar%%.jar}"
rm "${base}/${f}"
done
else
echo " - DIFFERENT"
fi
done
mkdir jars
( cd "common" ; jar -cvf "../jars/common.jar" * ; )
for jar in *.jar ; do
base="${jar%%.jar}"
( cd "$base" ; jar -cvfm "../jars/${jar}" META-INF/MANIFEST.MF * ; )
done
The resulting jar sizes for SWT version 4.3 are:
swt_common.jar 521865
swt_linux_x64.jar 1373413
swt_linux_x86.jar 1222447
swt_macosx_x64.jar 1416943
swt_macosx_x86.jar 1514651
swt_win32_x64.jar 1434927
swt_win32_x86.jar 1421738
Also remember, that doing a click-jar-to-run style SWT application for MacOS is tricky (the -XstartOnFirstThread option issue). So you might consider removing the MacOS platform.