UnsupportedClassVersionError: Bad version number in .class file
Hello guys...
I have a real problem I can't seem to figure out. I am using MyEclipse 2014 however I was originally using 9.0 and thought upgrading might solve the problem but it did not.
I am compiling inside of MyEclipse using Jdk1.6.0_45. I have checked all references on Tomcat 6.0 and within MyEclipse and all are using the same JAVA version. As a matter of fact it is the only version of JAVA on the server. I pointed MyEclipse to a full version of Tomcat 6.0 however prior to this I tried it with the MyEclipse sandbox version of Tomcat with the same results. I can run the web app using MyEclipse sandbox Tomcat and my full version of Tomcat and everything works fine but if try to fire up Tomcat outside of MyEclipse I get the bad version number class file error. This is really confusing because it is the same Web Server and files used by MyEclipse. I know this error can occur when the build JDK version is different than what is used by Tomcat but this is not the case and once again it works perfectly inside of MyEclipse using the same Tomcat but errors when I fire Tomcat up outside of MyEclipse. I have also tried to put the build on two other servers using Tomcat 6.0 with the same results.
Please any suggestions would be appreciated because I have checked every possible configuration I can think of.
rf
JavaWeb Servers
Last Comment
ivron001
8/22/2022 - Mon
dpearson
The only way you can get that error (at least to the best of my knowledge) is by using a different Java runtime from the JDK used to compile the files.
I know you say there's only one Java on the server, but the error you are getting suggests that may not be the case or somebody (e.g. MyEclipse) is setting either the -source or -target flags explicitly to override the defaults for the compiler. http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html#options
Anyway, what I'd suggest is first narrowing down the problem. Are the Jar files that you are creating actually from JDK 1.6 or not?
The way to tell is to create the JAR (or WAR or whatever), unpack it and then run
javap -verbose YourClass
for one of the classes inside and look at the output. Java 6 should have major version 50.
If you see a different version in there, you know the problem is on the compiler side - you're not actually generating JDK 1.6 output.
If you see that version in there, you know the problem in on the runtime side - you're not running it using JDK 1.6.
Knowing which side is confused should help.
Doug
ivron001
ASKER
Hi Doug...
I appreciate your response and agree with you. It would be helpful to know the version output however when I run javap -verbose on the offending class this is what I get listed below and I don't see the output version. I have removed all jar files except system dependents and still get the same results. If you can help me determine the version output I am sure I can figure the rest out.
Thanks
rf
javap -verbose output when ran
293: aastore
294: aload 9
296: iconst_0
297: aaload
298: iconst_3
299: ldc #144; //String searchtype
301: aastore
302: aload 9
304: iconst_0
305: aaload
306: iconst_4
307: ldc #146; //String searchvalue
309: aastore
310: aload 9
312: iconst_0
313: aaload
314: iconst_5
315: ldc #148; //String callingscreen
317: aastore
318: aload 9
320: iconst_0
321: aaload
322: bipush 6
324: ldc #150; //String primaryid
326: aastore
327: aload 9
329: iconst_0
330: aaload
331: bipush 7
333: ldc #152; //String rowid
335: aastore
336: aload 9
338: iconst_0
339: aaload
340: bipush 8
342: ldc #154; //String searchvalue2
344: aastore
345: aload 9
347: iconst_0
348: aaload
349: bipush 9
351: ldc #156; //String usesqlstatement
353: aastore
354: aload 9
356: iconst_1
357: aaload
358: iconst_0
359: ldc #67; //String
361: aastore
362: aload 9
364: iconst_2
365: aaload
366: iconst_0
367: ldc #67; //String
369: aastore
370: aload 9
372: iconst_3
373: aaload
374: iconst_0
375: ldc #67; //String
377: aastore
378: aload 9
380: iconst_4
381: aaload
382: iconst_0
383: ldc #67; //String
385: aastore
386: aload 9
388: iconst_5
389: aaload
390: iconst_0
391: ldc #67; //String
393: aastore
394: aload 9
396: bipush 6
398: aaload
399: iconst_0
400: ldc #67; //String
402: aastore
403: aload 9
405: bipush 7
407: aaload
408: iconst_0
409: ldc #67; //String
411: aastore
412: aload 9
414: bipush 8
416: aaload
417: iconst_0
418: ldc #67; //String
420: aastore
421: aload 8
423: aload 9
425: invokevirtual #158; //Method com/fasttrack/struts/common/User.setEnvir
onment:([[Ljava/lang/String;)V
428: ldc #162; //String projectname
430: ldc #100; //String FastTrack
432: invokestatic #164; //Method java/lang/System.setProperty:(Ljava/lang/
String;Ljava/lang/String;)Ljava/lang/String;
435: pop
436: aload_3
437: areturn
LineNumberTable:
line 108: 0
line 111: 8
line 113: 16
line 115: 22
line 116: 32
line 117: 37
line 119: 41
line 122: 49
line 125: 57
line 126: 87
line 128: 94
line 130: 108
line 131: 113
line 132: 122
line 135: 133
line 136: 140
line 138: 146
line 140: 162
line 141: 167
line 142: 173
line 144: 176
line 146: 190
line 147: 195
line 148: 204
line 151: 215
line 152: 230
line 153: 245
line 155: 260
line 157: 270
line 158: 278
line 159: 286
line 160: 294
line 161: 302
line 162: 310
line 163: 318
line 164: 327
line 165: 336
line 166: 345
line 168: 354
line 169: 362
line 170: 370
line 171: 378
line 172: 386
line 173: 394
line 174: 403
line 175: 412
line 177: 421
line 179: 428
line 189: 436
For some reason my command window was not showing what you displayed so I sent the output to a file and was able to see what was missing at the top. The major version was 50 so I tried compiling with jdk 5 instead of 6 compatibility mode and used Tomcat build with Jdk1.6.0_45 and got a usable build. I do have some version issues in my environment apparently happened during my original upgrade of MyEclipse which started all of this mess.
I was at a stand still and your suggestion got me started again so thanks a million. I should be able to resolve my problem now because I can identity the specific errors in conflict.
I know you say there's only one Java on the server, but the error you are getting suggests that may not be the case or somebody (e.g. MyEclipse) is setting either the -source or -target flags explicitly to override the defaults for the compiler.
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html#options
Anyway, what I'd suggest is first narrowing down the problem. Are the Jar files that you are creating actually from JDK 1.6 or not?
The way to tell is to create the JAR (or WAR or whatever), unpack it and then run
javap -verbose YourClass
for one of the classes inside and look at the output. Java 6 should have major version 50.
If you see a different version in there, you know the problem is on the compiler side - you're not actually generating JDK 1.6 output.
If you see that version in there, you know the problem in on the runtime side - you're not running it using JDK 1.6.
Knowing which side is confused should help.
Doug