Java – why do I get UnsupportedClassVersionError in jnlp


I get an UnsupportedClassVersionError thrown when launching jnlp, however when I try to run the relevant jar files from command line everything works fine. I tried setting j2se versions to 1.5+, 1.6+, using signed/unsigned jar files, but all that doesn't help.

I'm trying to launch my own jar file with two supporting jar files (mysql-connector.jar and swingx.jar). My jar file has been compiled with 1.6 compliance settings in Eclipse and built into a jar with ant. Since I can launch the 3 jars from command line using java 1.6 I'm a bit baffled that jnlp fails. Any help is appreciated.

Here is the jnlp file:

<?xml version="1.0" encoding="utf-8"?>
<!-- JNLP File -->
<jnlp spec="1.5+" codebase="" href="demo-daily.jnlp">
  <title>demo: daily stock charting utility</title>
  <j2se href="" version="1.6+" />
  <jar href="demo-daily.jar" main="true" />
  <jar href="swingx.jar" main="false" />
  <jar href="mysql-connector.jar" main="false" />
 <application-desc main-class="quipu.viewers.charts.stockcharts.daily"/>

The error I get is:

java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(
at Method)
at com.sun.jnlp.JNLPClassLoader.findClass(
at java.lang.ClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
at com.sun.javaws.Launcher.doLaunchApp(

Best Solution

First, open a CMD window or a shell window (as appropriate to the OS you're using) and type this:

java -version

to ensure that the version you're running is the version you expect to be running. Then, again from the command line, issue the command:

javaws http://host/path/to/your.jnlp

If you cannot run javaws from the command line, then you'll have to find out where it's installed and use the full path to the executable. Under Windows, this will be something like

C:\Program Files\Java\jre1.6.0_14\bin\javaws.exe

and under Linux it may be /usr/bin/javaws or it may be in another directory.

I know under Windows, at any rate, when you run any Java Web Start app, the JNLP loader is used from the most recent Java version installed. Or at least it's supposed to do this. I haven't experimented under Linux (or MacOS) to see how it works there. But it's always possible that something has gotten messed up and when you launch a JNLP you are accidentally running a Java 1.5 JNLP launcher.

You can always try to uninstall and re-install the most recent version of Java to ensure that the latest and greatest version is properly installed. This may fix things. You may also want to check your $PATH (or %PATH%) to ensure that the correct version of Java is on the path. (This is not always necessary ... but if any version of Java is on the path, ensure that it's the version you want.) Check the environment variable JAVA_HOME to make sure it points where you think it does.