1

Facing an issue while migrating Swing Application developed on JDK 6 to JDK 8 causes the below issue:

java.lang.NoClassDefFoundError: org/jdesktop/swingworker/SwingWorker
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
    at java.lang.Class.getMethod0(Class.java:3018)
    at java.lang.Class.getMethod(Class.java:1784)
    at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
    at com.sun.javaws.Launcher.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: org.jdesktop.swingworker.SwingWorker
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at com.sun.jnlp.JNLPClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 8 more

The application is using JNLP for the dependencies.

JNLP configuration:

<?xml version="1.0" encoding="utf-8"?>
<jnlp       spec="1.6+"     codebase="http://SERVER_NAME:8080/jnlp/" href="test.jnlp">
    <information>
        <title>Test</title>
        <vendor>ABC</vendor>
        <offline-allowed/>
    </information>
    <security>
        <all-permissions/>
    </security>
    <update check="always" policy="always" />
    <resources>
        <j2se version="1.6*" max-heap-size="512M" initial-heap-size="256m" href="http://java.sun.com/products/autodl/j2se" />
        <property name="weblogic.MaxMessageSize" value="2000000000"/>
        <!-- Environment -->
        <property name="env" value="test"/>
        <!-- SSO authentication parameters for DEBUGGING -->
        <property name="abc.xyx.debug" value="true"/>
        <property name="aaaa.rrrr.debug" value="true"/>
        <property name="tttt.rrrr.eee.enable" value="true"/>
        <jar href="libs/test-SNAPSHOT.jar" main="true"/>
        ..........SOME OTHER JAR's
        <jar href="libs/swingx-0.9.5.jar"/>
        <jar href="libs/swing-worker-1.1.jar"/>
       
    </resources>
    <resources os="Windows" arch="x86">
        <nativelib href="libs/XYZ-1.0.jar"/>
    </resources>
    <application-desc main-class="com.example.Login" />
</jnlp>

Anybody can help in this or suggest what are changes/improvement made in the JDK 8 regarding JNLP and Java Web Start.

Tech stack used: Java 8, Web Logic 12c

Thanks in advance :)

Update 1:

Just for RnD, executed the same build with same JNLP config on JDK 6, it is working fine but when I tried on run on JDK 8, getting below error: enter image description here

And when I run the app from the eclipse, it is working fine with JAVA 8 too.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
Atul Rai
  • 332
  • 1
  • 10
  • 25
  • `SwingWorker` is a class of the base JDK (`javax.swing.SwingWorker`). Not sure if your application was previously using a 3rd party version of that class. I would try to just get rid of the custom class. See: [Worker Thread and SwingWorker](https://docs.oracle.com/javase/tutorial/uiswing/concurrency/worker.html)(https://docs.oracle.com/javase/tutorial/uiswing/concurrency/worker.html) for more info. – camickr Sep 21 '21 at 13:38
  • 1
    I suppose, the `org.jdesktop.swingworker.SwingWorker` should be contained in the `libs/swing-worker-1.1.jar`. So you have to check whether there’s an issue with this resource. – Holger Sep 21 '21 at 14:28

2 Answers2

3

According to Wikipedia, org.jdesktop.swingworker.SwingWorker is a backport of the javax.swing.SwingWorker class introduced in Java 6.

The Wikipedia page for SwingWorker that states:

A backport of the Java 6 SwingWorker to Java 5 is available at http://swingworker.java.net/[permanent dead link]. Apart from the package name (org.jdesktop.swingworker), it is compatible with the Java 6 SwingWorker.

The original home for this package on java.net has gone. (But you may have some luck with the Wayback Machine archive.)

I found a couple of entries on Maven Central, but one of those is offline too.


So, it looks like there are two options:

  1. By far the best option would be to modify your project to use the official javax.swing.SwingWorker. It should be a simple change. Just change the import statement(s). Once you have done this you can forget about this problem forever.

  2. If you still had to support your application on Java 5 and earlier, then you would need to find a JAR file for this dependency and add it to your project. Try Maven Central.


For information about other org.jdesktop.* dependencies, see the answers to Eclipse does not recognize org.jdesktop.*.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • See also this [archive](https://web.archive.org/web/20110215162655/http://java.net/projects/swingworker); option one works under Java 11 on a demo from the era by replacing package private access with `import javax.swing.SwingWorker;`. – trashgod Sep 22 '21 at 01:56
  • *"... by replacing package private access ..."* - Not quite sure what you mean there. The old `org.jdesktop.swingworker.SpringWorker` class is / was `public`. Albeit a 3rd-party class. – Stephen C Sep 22 '21 at 02:28
  • Hi All, I have tried all the possible way to make it compactible with JDK 8 but still getting the same error. org.jdesktop.swingworker.SwingWorker is third party class under the swing-worker-1.1.jar – Atul Rai Sep 22 '21 at 04:44
  • Maybe `swingx` depends on that `SwingWorker`. From what I can tell, it is a subproject of this: https://en.wikipedia.org/wiki/SwingLabs . As you can see SwingLabs is 10 years out of date ... and in the same situation as `org.jdesktop.swingworker`. Basically defunct. You should probably try to remove that dependency and (where necessary) replace it with `javax.swing` classes. (Porting ancient code with dependencies that are no longer supported is not a simple thing. It may require significant Java dev effort.) – Stephen C Sep 22 '21 at 05:12
  • When I start the application on local machine with JDK 8, it is working fine with Web logic 12c server but in this case all the required dependencies provided locally (build-path) but when I deploy on the server, its is not starting and throwing the above exception . Is there any issue/changes/improvement related to the JNLP calling to load the dependencies in Java 8? – Atul Rai Sep 22 '21 at 05:49
  • 1
    All of the dependency resources need to be in the appropriate place on the server so that they can be downloaded when required. Have you checked that? Have you checked the server-side logs to see what files are being fetched by the client to see if the JARs are being requested ... and what the server response was? – Stephen C Sep 22 '21 at 07:15
  • I have checked, all the resources are at appropriate place and when I execute the javaws -viewer command, resources are there. The problem with JDK 8 version that I still not able to figure it out. Just for R&D, I have executed the same build with same JNLP configuration on JDK 6, it is working perfectly. Any lead will be much appreciated. Thanks in Advance – Atul Rai Oct 07 '21 at 06:58
1

As shown here and here, org.jdesktop.swingworker is a back-port of SwingWorker for Java 5. The code is preserved here and here.

It should be possible to remove the dependency:

<jar href="libs/swing-worker-1.1.jar"/>

And import the standard implementation:

import javax.swing.SwingWorker;

As a concrete example, PrimeNumbersDemo compiles and runs stand-alone under Java 8 and 11 by removing the package declaration and adding the import.

 //package org.jdesktop.swingworker;
 import javax.swing.SwingWorker;

As an aside, the package declaration had the effect of giving the demo package-private access to the SwingWorker class without an explicit import.

image

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • Any idea why JAR is not loading while calling application through JNLP and throw ClassNotFoundExp? – Atul Rai Oct 08 '21 at 09:19
  • Which JAR: the one containing `org/jdesktop/swingworker/SwingWorker` or the one containing `javax.swing.SwingWorker`? Maybe [this](https://stackoverflow.com/a/6928154/230513) might shed light. – trashgod Oct 08 '21 at 17:50
  • JAR which contain org/jdesktop/swingworker/SwingWorker. I have replaced this with Java SwingWorker and Caused by: java.lang.ClassNotFoundException: org.jdesktop.swingworker.SwingWorker is now gone but in the project we have other several JAR's non of them loading and throwing java.lang.ClassNotFoundException. P.S. Same build is working/running fine with JDK 6 on weblogic 12c server, the problem is only with JDK 8. – Atul Rai Oct 12 '21 at 04:48