我能够将程序编译为jar文件,它只有一个类。我必须创建一个批处理文件,以便我可以运行jar而不必直接使用控制台。我在那里使用的代码是java -cp game.jar game
这使我可以在运行批处理文件的计算机上运行程序。但是,当我将jar和批处理文件发送给朋友以便他可以运行它时,控制台就会闪烁。我让他安装了JRE,因为我猜想这可能是问题所在,但它没有解决问题。我的程序代码是'无法在一台计算机上运行jar,但可以在另一台计算机上运行
公共类游戏{
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)
{
}
}
{
当它们从命令行(而不是您的批处理文件)运行jar文件时它对你的朋友有用吗?他是否以这种方式在命令行中收到任何错误消息? – Thilo
*从独立的命令行启动*程序与'java'。阅读错误信息。 – user2864740
回家好运。 – Stanton