Avatar of ivron001
ivron001
 asked on

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

Avatar of undefined
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

  LocalVariableTable:
   Start  Length  Slot  Name   Signature
   0      438      0    this       Lcom/fasttrack/struts/form/LogonForm;
   0      438      1    mapping       Lorg/apache/struts/action/ActionMapping;
   0      438      2    request       Ljavax/servlet/http/HttpServletRequest;
   8      430      3    errors       Lorg/apache/struts/action/ActionErrors;
   16      422      4    session       Ljavax/servlet/http/HttpSession;
   32      406      5    sSubmitType       Ljava/lang/String;
   108      328      6    table       Lcom/fasttrack/struts/global/Tables;
   162      274      7    aRec       [[Ljava/lang/String;
   190      246      8    user       Lcom/fasttrack/struts/common/User;
   270      166      9    aValues       [[Ljava/lang/String;

  StackMapTable: number_of_entries = 5
   frame_type = 254 /* append */
     offset_delta = 41
     locals = [ class org/apache/struts/action/ActionErrors, class javax/servlet
/http/HttpSession, class java/lang/String ]
   frame_type = 252 /* append */
     offset_delta = 91
     locals = [ class com/fasttrack/struts/global/Tables ]
   frame_type = 252 /* append */
     offset_delta = 42
     locals = [ class "[[Ljava/lang/String;" ]
   frame_type = 252 /* append */
     offset_delta = 38
     locals = [ class com/fasttrack/struts/common/User ]
   frame_type = 248 /* chop */
     offset_delta = 220


public boolean validateUser(java.lang.String, java.lang.String);
  Code:
   Stack=1, Locals=4, Args_size=3
   0:   iconst_0
   1:   istore_3
   2:   iload_3
   3:   ireturn
  LineNumberTable:
   line 193: 0
   line 207: 2

  LocalVariableTable:
   Start  Length  Slot  Name   Signature
   0      4      0    this       Lcom/fasttrack/struts/form/LogonForm;
   0      4      1    sUser       Ljava/lang/String;
   0      4      2    sPassword       Ljava/lang/String;
   2      2      3    bIsMore       Z


public java.lang.String getUserid();
  Code:
   Stack=1, Locals=1, Args_size=1
   0:   aload_0
   1:   getfield        #26; //Field userid:Ljava/lang/String;
   4:   areturn
  LineNumberTable:
   line 214: 0

  LocalVariableTable:
   Start  Length  Slot  Name   Signature
   0      5      0    this       Lcom/fasttrack/struts/form/LogonForm;


public void setUserid(java.lang.String);
  Code:
   Stack=2, Locals=2, Args_size=2
   0:   aload_0
   1:   aload_1
   2:   putfield        #26; //Field userid:Ljava/lang/String;
   5:   return
  LineNumberTable:
   line 222: 0
   line 223: 5

  LocalVariableTable:
   Start  Length  Slot  Name   Signature
   0      6      0    this       Lcom/fasttrack/struts/form/LogonForm;
   0      6      1    userid       Ljava/lang/String;


public java.lang.String getErrmsg();
  Code:
   Stack=1, Locals=1, Args_size=1
   0:   aload_0
   1:   getfield        #28; //Field errmsg:Ljava/lang/String;
   4:   areturn
  LineNumberTable:
   line 230: 0

  LocalVariableTable:
   Start  Length  Slot  Name   Signature
   0      5      0    this       Lcom/fasttrack/struts/form/LogonForm;


public void setErrmsg(java.lang.String);
  Code:
   Stack=2, Locals=2, Args_size=2
   0:   aload_0
   1:   aload_1
   2:   putfield        #28; //Field errmsg:Ljava/lang/String;
   5:   return
  LineNumberTable:
   line 238: 0
   line 239: 5

  LocalVariableTable:
   Start  Length  Slot  Name   Signature
   0      6      0    this       Lcom/fasttrack/struts/form/LogonForm;
   0      6      1    errmsg       Ljava/lang/String;


public boolean isFirstTime();
  Code:
   Stack=1, Locals=1, Args_size=1
   0:   aload_0
   1:   getfield        #30; //Field isFirstTime:Z
   4:   ireturn
  LineNumberTable:
   line 246: 0

  LocalVariableTable:
   Start  Length  Slot  Name   Signature
   0      5      0    this       Lcom/fasttrack/struts/form/LogonForm;


public void setFirstTime(boolean);
  Code:
   Stack=2, Locals=2, Args_size=2
   0:   aload_0
   1:   iload_1
   2:   putfield        #30; //Field isFirstTime:Z
   5:   return
  LineNumberTable:
   line 253: 0
   line 254: 5

  LocalVariableTable:
   Start  Length  Slot  Name   Signature
   0      6      0    this       Lcom/fasttrack/struts/form/LogonForm;
   0      6      1    b       Z


}


C:\Program Files\Java\jdk1.6.0_45\bin>
ASKER CERTIFIED SOLUTION
dpearson

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ivron001

ASKER
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.

rf
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23