views:

1156

answers:

5

I try to compile a webtools project for Java5/Tomcat 5.5 in ubuntu (with manually installed eclipse 3.4). I set the installed jre to java-1.5.0-sun-1.5.0.18 and the compiler compliance level to 1.5. When I export this to a .war file, and try to deploy it in Tomcat (Windows XP, Tomcat 5.5.27, Java 1.5.0_18) , I get the following error:

SEVERE: Error deploying web application archive Jdbc2Ei.war
java.lang.UnsupportedClassVersionError: Bad version number in .class file
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
...

Anybody knows how to solve this?

+1  A: 

java.lang.UnsupportedClassVersionError: Bad version number in .class file

check that all your jars are compiled for java5.

dfa
Checked it... that was NOT the problem :(
Jack Ha
A: 

Compiled it under windows, and it works! Some bug somewhere... there will be a time that this problem will be fixed.

Jack Ha
A: 

If it works in Windows, it's probably due to a difference in environments rather than a bug present in the Linux versions of the JDKs. Check to see if you have multiple JVMs present in Linux (you almost certainly do, since Ubuntu probably comes with a non-Sun version) and be 110% sure that you're using the expected version to compile. Issuing

which javac

and

echo $JAVA_HOME; echo $JDK_HOME

from a command-line might help too, since all of these could feasibly be used to locate a JDK (as well as the settings you use in your compile command/tool).

Andrzej Doyle
I tried java-1.5.0-sun-1.5.0.18, java-6-openjdk, java-6-sun-1.6.0.13. Each of them produced a slightly different war, but none of them worken...
Jack Ha
A: 

Your tomcat is running a lesser JDK than the one used to compile some of your classes. Recompile with a compatible JDK or upgrade the JRE for the tomcat.

mP
A: 

A naive one: After changing project preferences and before exporting the WAR file on Ubuntu, did you try to force compile on your projects ( Project -> Clean... in Eclipse) ?

david a.
Yes, different times with different compile settings!
Jack Ha