Problems in running jar on Amazon ec2 [duplicate]

2019-09-17 08:09发布

This question already has an answer here:

Hi I have a java project in eclipse. The main class as follows:

package aws;

public class Assignment3 {
public static void main(String[] args) throws Exception { }
}

My manifest file is:

Manifest-Version: 1.0
Class-Path: aws.Assignment3

I exported my executable jar with scp to my ec2 successfully. When I try to run my jar I get:

[ec2-user@ip-10-138-8-38 project]$ java -jar alertShopper.jar
Exception in thread "main" java.lang.UnsupportedClassVersionError: aws/Assignment3 : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: aws.Assignment3. Program will exit.

I did

[ec2-user@ip-10-138-8-38 project]$ java -version
java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9.1) (amazon-44.1.9.1.16.amzn1-i386)
OpenJDK Client VM (build 19.0-b06, mixed mode)

I don't know what else to do. Any help will be appreciated. Thanks

I now got a new ec2 amazon ami and it has java 1.7 installed. But I need install jre-1.7 on amazon linux ami.

2条回答
太酷不给撩
2楼-- · 2019-09-17 08:37

All done did sudo yum install jre-1.7.0-openjdk and changed to java 1.7.

查看更多
劫难
3楼-- · 2019-09-17 08:38

Unsupported major.minor version 51.0

This issue happens when java version used to compile your code is different than version you are running your code on. Higher version of JDK during compile time and lower version JDK during runtime.

You may need to specify -target if you want to run lower version

查看更多
登录 后发表回答