0
votes

I have a java webstart application which uses swt for the interface (and includes DJ Native Swing). The application runs fine on windows, until I try to add the linux and mac osx swt jars to the application in order to support those platforms. The application runs fine under linux when started from netbeans with only the correct jars linked, but when launching the application through java webstart on any platform, it seems the wrong jar files are loaded.

This is what i have in my launch.jnlp (among other stuff):

<resources os="Windows" arch="x86">
    <j2se java-vm-args="-Xmx512m" version="1.5+"/>
    <jar href="lib/swt-win32-x86.jar"/>
    <nativelib href="lib/swt-win32-x86.jar"/>
</resources>

<resources os="Windows" arch="x86_64">
    <j2se java-vm-args="-Xmx512m" version="1.5+"/>
    <jar href="lib/swt-win32-x86_64.jar"/>
    <nativelib href="lib/swt-win32-x86_64.jar"/>
</resources>

<resources os="Windows" arch="amd64">
    <j2se java-vm-args="-Xmx512m" version="1.5+"/>
    <jar href="lib/swt-win32-x86_64.jar"/>
    <nativelib href="lib/swt-win32-x86_64.jar"/>
</resources>

<resources os="Linux" arch="i386">
    <j2se java-vm-args="-Xmx512m" version="1.5+"/>
    <jar href="lib/swt-linux-x86.jar"/>
    <nativelib href="lib/swt-linux-x86.jar"/>
</resources>

<resources os="Linux" arch="amd64">
    <j2se java-vm-args="-Xmx512m" version="1.5+"/>
    <jar href="lib/swt-linux-x86_64.jar"/>
    <nativelib href="lib/swt-linux-x86_64.jar"/>
</resources>

<resources os="Mac OS X" arch="x86_64">
    <j2se java-vm-args="-XstartOnFirstThread -Xmx512m" version="1.5+"/>
    <jar href="lib/swt-macos-x86_64.jar"/>
</resources>

<resources os="Mac OS X" arch="x86">
    <j2se java-vm-args="-XstartOnFirstThread -Xmx512m" version="1.5+"/>
    <jar href="lib/swt-macos.jar"/>
</resources> 

If I understand correctly, this should result in on windows (depending on the arch) only the swt-win32-x86.jar being loaded. But when I launch the application on windows 7 64bit, but with a 32bit jvm I get the following error: NativeSwing[1]: Caused by: java.lang.UnsatisfiedLinkError: Could not load SWT library. Reasons: NativeSwing[1]: no swt-gtk-4234 in java.library.path NativeSwing[1]: no swt-gtk in java.library.path NativeSwing[1]: Can't load library: C:\Users\dolf.swt\lib\win32\x86\swt-gtk-4234.dll NativeSwing[1]: Can't load library: C:\Users\dolf.swt\lib\win32\x86\swt-gtk.dll

Of course no swt-gtk can be found on Windows, it should only be needed on Linux. If I check the Resources in the java control panel under the temporary internet files viewer of java, I indeed see both swt-linux-x86.jar and swt-win32-x86.jar have been downloaded by java webstart. Clearly, java webstart is downloading the wrong jar files.

I hope anyone has an idea why this is going wrong.

1
"Cheers, Dolf." That's 4 lines of noise. Leave sigs. out of questions. 2) "Why is this going wrong?" is a question that might be inferred from that load of words. Is that your question? If so, add it as an edit alternately form an explicit question & edit that into the ..question. - Andrew Thompson

1 Answers

0
votes

I have found out what the problem was.

In Netbeans, I had the swt jar files linked under "libraries". I have limited understanding of how these things work in netbeans/java (I am not a java developper as can be inferred from the question), but I guess this causes all linked swt libraries to be downloaded, irrespective of whatever the launch.jnlp specifies. Hence the wrong jar files on the wrong platforms.

What needs to be done when building is EXCLUDE the swt jars from the list of libraries in netbeans, and then specify the resources in the jnlp file. This way, webstart will download only the swt jars found in the applicable resources tag.

If you need to sign them as well, add the following section to your build.xml, which makes sure the swt jar files are copied to the dist/lib dir, before signing starts, so netbeans will automatically sign them (every jar in the dist/lib dir is signed normally).

<target name="-post-jar">
    <copy todir="${jnlp.dest.dir}/lib/">
        <fileset dir="${build.dir}/../lib/">
            <filename name="swt*.jar" />
        </fileset>
    </copy>

</target>