tags:

views:

458

answers:

2

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="http://www.etc.com/p" href="demo-daily.jnlp">
 <information>
  <title>demo: daily stock charting utility</title>
  <offline-allowed/>
 </information>
 <security>
 </security>
 <resources>
  <j2se href="http://java.sun.com/products/autodl/j2se" version="1.6+" />
  <jar href="demo-daily.jar" main="true" />
  <jar href="swingx.jar" main="false" />
  <jar href="mysql-connector.jar" main="false" />
 </resources>
 <application-desc main-class="quipu.viewers.charts.stockcharts.daily"/>
</jnlp>

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(ClassLoader.java:675) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124) at java.net.URLClassLoader.defineClass(URLClassLoader.java:260) at java.net.URLClassLoader.access$100(URLClassLoader.java:56) at java.net.URLClassLoader$1.run(URLClassLoader.java:195) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at com.sun.jnlp.JNLPClassLoader.findClass(JNLPClassLoader.java:256) at java.lang.ClassLoader.loadClass(ClassLoader.java:316) at java.lang.ClassLoader.loadClass(ClassLoader.java:251) at com.sun.javaws.Launcher.doLaunchApp(Launcher.java:1052) at com.sun.javaws.Launcher.run(Launcher.java:105) at java.lang.Thread.run(Thread.java:613)

A: 

Just a guess, but update the opening tag to reference spec="1.6+"

<jnlp spec="1.6+" codebase="http://www.etc.com/p" href="demo-daily.jnlp">
AgileJon
Shouldn't make a difference, as this specifies the JNLP file format version. The OP already correctly specifies <j2se ... version="1.6+" />.
Eddie
+1  A: 

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.

Eddie
Thanks for your answer Eddie. I was under the assumption that web start would download the required JRE and run it, if not available on the system. I updated to latest JRE on my mac and I'm passed this problem -- thanks for your help!