java - 无法在一台计算机上运行 jar,但可以在另一台计算机上运行

标签 java batch-file jar

我能够将程序编译成 jar 文件,它只有一个类。我必须制作一个批处理文件,以便我可以运行该 jar,而不必直接使用控制台。我在那里使用的代码是 java -cp game.jar game 这允许我通过运行批处理文件在我的计算机上运行该程序。但是,当我将 jar 和批处理文件发送给 friend 以便他可以运行它时,控制台只是闪烁。我让他安装 JRE,因为我猜这可能是问题所在,但并没有解决问题。我的程序代码是`

公开课游戏{

public static void main(String[] args)
{
    // TODO Auto-generated method stub
        System.out.println("+------------------------------------------------+");
        System.out.println("|___       ___          ___  __   ___       __   |");
        System.out.println("| |  |__| |__     |    |__  / _` |__  |\\ | |  \\  |");
        System.out.println("| |  |  | |___    |___ |___ \\__> |___ | \\| |__/  |");
        System.out.println("|                                                |");
        System.out.println("|Made by Noah Baker                              |");
        System.out.println("|                                    *Pre-Alpha* |");
        System.out.println("+------------------------------------------------+");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException ie) {
        }

        System.out.println("+------------------------------------------------+");
        System.out.println("|There once was a fabled legendary item that if  |");
        try {
            Thread.sleep(3000);
        } catch (InterruptedException ie) {
        }

        System.out.println("|placed into the wrong hands could reek havoc.   |");
        try {
            Thread.sleep(2000);
        } catch (InterruptedException ie) {
        }

        System.out.println("|This item could destroy the very fabric of      |");
        try {
            Thread.sleep(3000);
        } catch (InterruptedException ie) {
        }

        System.out.println("|of space and time unless...                     |");
        try {
            Thread.sleep(2000);
        } catch (InterruptedException ie) {
        }

        System.out.println("|unless...                                       |");
        try {
            Thread.sleep(3000);
        } catch (InterruptedException ie) {
        }

        System.out.println("Okay. I'm done with this.");

        try {
            Thread.sleep(2000);
        } 
        catch (InterruptedException ie) 
        {
        }  
        System.out.println("This \"game\" is nothing even close to one.");
        try {
            Thread.sleep(4000);
        } 
        catch (InterruptedException ie) 
        {
        }
        System.out.println("Dana, you mean more to me than any game or thing could ever come close to.");
        try {
            Thread.sleep(3000);
        } 
        catch (InterruptedException ie) 
        {
        } 
        System.out.println("You are so absoulutely amazing and I am so incredibly lucky to be able to have");
        System.out.println("had you as mine for the past 3 months.");
        try {
            Thread.sleep(5000);
        } 
        catch (InterruptedException ie) 
        {
        }
        System.out.println("The past three months have been some of the greatest.");
        try {
            Thread.sleep(3000);
        } 
        catch (InterruptedException ie) 
        {
        }
        System.out.println("I just have one question to ask you.");
        try {
            Thread.sleep(3000);
        } 
        catch (InterruptedException ie) 
        {
        }
        System.out.println("Do you want to go to Homecoming with me?");
        System.out.println("     ******       ******");
        System.out.println("   **********   ********** ");
        System.out.println(" ************* *************");
        System.out.println("*****************************");
        System.out.println("*****************************");
        System.out.println("*****************************");
        System.out.println(" ***************************");
        System.out.println("   ***********************");
        System.out.println("     *******************");
        System.out.println("       ***************  ");
        System.out.println("         ***********    ");
        System.out.println("           *******      ");
        System.out.println("             ***        ");
        System.out.println("              *         ");
        try {
            Thread.sleep(6000);
        } 
        catch (InterruptedException ie) 
        {
        }
    }
{

最佳答案

让您的 friend 从命令提示符中运行批处理文件。然后他们应该能够查看(并可能向您发送)错误消息。

收到 friend 发来的错误消息

Exception in thread "main" java.lang.UnsupportedClassVersionError: game : Unsuported major.minor version 52.0 at
java.lang.ClassLoader.defineClass1(Native Method) at 
java.lang.ClassLoader.defineClass(Unknown Source) at
java.security.SecureClassLoader.defineClass(Unknown Source) at
java.net.URLClassLoader.defineClass(Unknown Source) at
java.net.URLClassLoader.access$100(Unknown Source)

建议

您的 friend 可能拥有旧版本的 JRE。使用旧版本的 Java 编译代码。

关于java - 无法在一台计算机上运行 jar,但可以在另一台计算机上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32342605/

相关文章:

java - 如何将 .class 文件添加到 Eclipse 项目 bin 文件夹中

java - 如何从 eclipse 导出为可运行 JAR 文件?

java - 在 Java 中访问 super() 类的私有(private)变量 - JChart2D

java - 在 Spring MVC 应用程序中使用 FB 登录 - 默认表的用途是什么?

windows - 如何在 Windows 批处理文件中包含带有多行 var 的回车符?

batch-file - 为什么这个带有多个文字搜索字符串的 FINDSTR 示例没有找到匹配项?

java - 在 javafx 中向文本字段添加特殊字符

java - Android 相机预览 byte[] 到 Java 图片

python - 在视频 ffmpeg 批处理脚本中显示文件名

java - 如何以编程方式搜索某个 JAR 中的文件?