简体   繁体   English

我的jar文件无法执行

[英]My jar file will not execute

File PrintTest.java : 文件PrintTest.java

    public class PrintTest{
      public static void main(String[] args){
           System.out.println("Why are you executing me?");
      }
    }

File Manifest.txt 文件Manifest.txt

Main-Class: PrintTest

My command I ran to compress to .jar : 我运行的命令压缩为.jar

jar cfm PrintTest.jar Manifest.txt PrintTest.class

I also tried this (even though it doesn't matter): 我也尝试过这个(尽管没关系):

jar cmf PrintTest.jar Manifest.txt PrintTest.class

My Directory Structure: C:\\Program Files\\Java\\jdk1.6.0_24\\PrintTest_jar 我的目录结构: C:\\Program Files\\Java\\jdk1.6.0_24\\PrintTest_jar

PrintTest_jar : PrintTest.java , PrintTest.class , Manifest.txt , PrintTest.jar PrintTest_jarPrintTest.javaPrintTest.classManifest.txtPrintTest.jar

When I double-click on the .jar file, nothing happens. 当我双击.jar文件时,没有任何反应。 No errors, nothing. 没有错误,没事。

PrintTest.class runs fine from the command line. PrintTest.class运行良好。 I'm also running on Windows. 我也在Windows上运行。

When I double-click on the .jar file, nothing happens. 当我双击.jar文件时,没有任何反应。 No errors, nothing! 没有错误,没事!

When launched like that, the console window will immediately disappear when the program has finished executing. 像这样启动后,控制台窗口将在程序完成执行后立即消失。 To see the output, you should run the program from the console instead of double clicking the jar file. 要查看输出,应该从控制台运行该程序,而不是双击jar文件。

edit : To delay the program termination, you could do this: 编辑 :要延迟程序终止,您可以这样做:

 Scanner scanner = new Scanner(System.in);
 System.out.print("Press Enter to exit...");
 scanner.next();

However, I think it makes more sense to just run console applications from the console. 但是,我认为仅从控制台运行控制台应用程序更有意义。

亲爱的朋友,您的应用程序是DOS程序,只能在DOS中运行,您没有创建GUI程序,如果是GUI程序,则至少会在计算机上显示..... DOS是用于DOS的。 .....对不起。

The code that was given to you to delay it is correct . 提供给您以延迟它的代码是正确的 However, you need to import an utility from Java libraries for it to work. 但是,您需要从Java库导入实用程序才能使它起作用。 Type in this before even your class body. 在您的班级正文之前输入此内容。

import java.util.Scanner

If I understand your question and the display of your manifest text file then you must ensure that the text file contains a new-line after the last line of text or it will not be processed properly. 如果我理解您的问题和清单文本文件的显示,那么您必须确保该文本文件在最后一行文本之后包含换行符,否则将无法正确处理。 Please see this for more info: http://download.oracle.com/javase/tutorial/deployment/jar/modman.html 请查看此以获得更多信息: http : //download.oracle.com/javase/tutorial/deployment/jar/modman.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM