1

I created a program in java using a tutorial from NetBeans, and it works great in Windows. However, when I attempt to run the same .jar in Linux (RedHat) I get the following exception:

Exception in thread "main" java.lang.UnsupportedClassVersionError: JVMCFRE003 bad major version; class=my/numberaddition/NumberAdditionUI, offset=6

From running this command:

java -jar NumberAddition.jar

The output ends with:

Could not find the main class: my.numberaddition.NumberAdditionUI. Program will exit.

The source code for this example can be found here. What am I missing?

Edit: Is there something I need to add for portability between operating systems?

Edit, answer: Thanks for the commenters who left possible duplicate links. From those and some further research I was able to determine that the JRE on the Linux environment was an older version (1.6) than the version I compiled the program in originally (1.7).

Bts
  • 107
  • 1
  • 9
  • 1
    possible duplicate: http://stackoverflow.com/questions/14926402/unsupportedclassversionerror-jvmcfre003-bad-major-version-in-websphere-as-7 – Dan O Jul 02 '13 at 14:52
  • Are you with OpenJDK in RedHat Linux? – Federico Zancan Jul 02 '13 at 14:54
  • 1
    possible duplicate: http://stackoverflow.com/questions/6066103/what-is-the-reason-for-unsupportedclassversionerror – Andreas Fester Jul 02 '13 at 14:55
  • @orzechowskid I am not using WebSphere Application Server V7 which seems to be the source of the problem at your linked question. Could there possibly be some connection? The answer there is also rather unclear as to how to fix the issue. – Bts Jul 02 '13 at 14:56
  • I believe the default JDK on Redhat is the OpenJDK which would likely have issues running in a Websphere instance. Best fix would be to get the IBM JDK or or Oracle JDK downloaded and compile it again using that. – Durandal Jul 02 '13 at 15:02

2 Answers2

2

Check your Java version in your RedHat box.

java -version

The exception you are seeing is related to the JVM trying to run a bytecode that has been compiled with a later version of the JDK.

Update your Java version on RedHat by downloading it from Oracle or using yum to obtain a version of the JDK which is suitable with what you compiled.

Or rebuild your software on RedHat ;) if your code is not relying on later versions language enhancements.

Federico Zancan
  • 4,846
  • 4
  • 44
  • 60
0

From running this command:

java -jar NumberAddition.jar

The output ends with:

Could not find the main class: my.numberaddition.NumberAdditionUI. Program will exit.

While executing jar with java -jar, main class need to be mentioned in manifest file or full path to the main class should be specified putting jar file in classpath

For eg: if my.numberaddition.MainClass is your main class ... run as

java -cp NumberAddition.jar my.numberaddition.MainClass

roshan
  • 160
  • 1
  • 7