简体   繁体   中英

Could not find the main class running jar

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM