gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 13:29:23 25 4
gpt4 key购买 nike

我能够将程序编译成 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com