本文介绍了在Amazon EC2上运行的jar问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有一个Eclipse Java项目。主类,如下所示:

 包AWS;

公共类Assignment3 {
公共静态无效的主要(字串[] args)抛出异常{}
}
 

我的清单文件是:

 清单-版本:1.0
类路径:aws.Assignment3
 

我出口我的可执行的JAR与SCP到我的EC2成功。当我尝试运行我的瓶子,我得到:

  [EC2用户@ IP-10-138-8-38项目] $ Java的罐子alertShopper.jar
在线程异常主要因为java.lang.UnsupportedClassVersionError:AWS / Assignment3:不支持为major.minor版本51.0
    在java.lang.ClassLoader.defineClass1(本机方法)
    在需要java.lang.ClassLoader.defineClass(ClassLoader.java:634)
    在java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    在java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
    在java.net.URLClassLoader.access $ 000(URLClassLoader.java:73)
    在java.net.URLClassLoader的$ 1.运行(URLClassLoader.java:212)
    在java.security.AccessController.doPrivileged(本机方法)
    在java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    在java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    在sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:294)
    在java.lang.ClassLoader.loadClass(ClassLoader.java:266)
找不到主类:aws.Assignment3。计划将退出。
 

我做了

  [EC2用户@ IP-10-138-8-38项目] $ Java的版本
Java版本1.6.0_20
OpenJDK的运行时环境(IcedTea6 1.9.1)(亚马逊44.1.9.1.16.amzn1-I386)
OpenJDK的客户端虚拟机(建设19.0  -  B06,混合模式)
 

我不知道自己还能做些什么。任何帮助将AP preciated。谢谢

我现在有一个新的亚马逊的EC2 AMI和它安装的Java 1.7。但我需要在亚马逊的Linux AMI安装JRE - 1.7。

解决方案

在Java版本用于编译code是比你运行你的code版本不同发生此问题。更高版本的JDK版本在编译时和低版本的JDK运行时。

您可能需要指定-target如果你想运行低版本

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.

解决方案

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

这篇关于在Amazon EC2上运行的jar问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 03:12