2015-09-01 175 views
1

我能够将程序编译为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) 
     { 
     } 
    } 
{ 
+0

当它们从命令行(而不是您的批处理文件)运行jar文件时它对你的朋友有用吗?他是否以这种方式在命令行中收到任何错误消息? – Thilo

+2

*从独立的命令行启动*程序与'java'。阅读错误信息。 – user2864740

+1

回家好运。 – Stanton

回答

0

请你的朋友从命令提示符中运行该批处理文件。然后,他们应该能够查看(并可能发送给您)错误消息。从朋友收到

错误消息

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) 

咨询

你的朋友可能有JRE的旧版本。用旧版Java编译你的代码。

+0

异常线程 “main” 因为java.lang.UnsupportedClassVersionError:游戏:UNSUP orted MAJOR.MINOR版本52.0 在java.lang.ClassLoader.defineClass1(本机方法) 在需要java.lang.ClassLoader.defineClass(来源不明) 在java.net.URLClassLoader.defineClass(未知源) 在java.net.URLClassLoader.access $ 100(未知源) –

+0

在java.net.URLClassLoader $ 1.run(来源不明) 在java.net.URLClassLoader的$ 1.run(来源不明) 在java.security.AccessController.doPrivileged(本机方法) 在java.net.URLClassLoader.findClass(来源不明) 在java.lang.ClassLoader.loadClass(来源不明) 在sun.misc.Launcher $ AppClassLoader.loadClass(来源不明) 在java.lang.ClassLoader.loadClass(来源不明) 在sun.launcher.LauncherHelper.checkAndLoadMain (未知来源) –

+3

看起来像使用比您的朋友拥有的JRE更高版本的Java编译应用程序。 – Jason

相关问题