Problems in running jar on Amazon ec2 [duplicate]

£可爱£侵袭症+ 提交于 2019-12-25 02:44:14

问题


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.


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/20669862/problems-in-running-jar-on-amazon-ec2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!