简体   繁体   English

当我将Java导出为可运行的jar文件时,不起作用

[英]When i export my java as runnable jar file, do not work

i have tried so many times to not post this question by searching my problem solution but i am failed , 我已经尝试了很多次,不通过搜索我的问题解决方案来发布此问题,但是我失败了

i am new to java, i am facing a problem,that i want a runnable java application and 我是Java新手,我遇到一个问题,我想要一个可运行的Java应用程序,并且

when i tried to export it into runnable it does not execute. 当我尝试将其导出到可运行时,它不执行。 i am using Eclipse for java. 我正在使用Eclipse for Java。

My code is 我的代码是

package hello;

public class HelloWorld {

public static void main(String[] args) {


    System.out.println("Hello World");

   }

}

Since there no code to pause the screen so it may be the case that JAR file is getting executed but you are not able to see the output window. 由于没有代码来暂停屏幕,因此可能是JAR文件正在执行但您看不到输出窗口的情况。 Check it with some pause statement. 用一些暂停语句检查它。 May be you can use Thread.sleep(x) for wait. 可能您可以使用Thread.sleep(x)等待。

There are at least 3 ways to execute a JAR: 至少有3种执行 JAR的方法:

  1. double-click on it, obviously Java must be (correctly) installed and the system support double-clicking (has a mouse and a graphical interface, eg Windows) - this does not open a console and you would not see any output going to System.out, like in your code. 双击它,显然必须(正确)安装Java,并且系统支持双击(具有鼠标和图形界面,例如Windows)-这不会打开控制台,您将看不到任何输出到System .out,就像您的代码中一样。

    In that case you could add a statement as JOptionPane.showMessage(null, "Hello World!"); 在这种情况下,您可以将语句添加为JOptionPane.showMessage(null, "Hello World!"); that opens a dialog and shows the given message; 打开一个对话框并显示给定的消息;

  2. java -jar <file.jar> this executes the jar opening a console - you will see what is going to System.out; java -jar <file.jar>这将执行jar,打开一个控制台-您将看到进入System.out的内容;

  3. javaw -jar <file.jar> same as above but without console - text written to System.out will be lost! javaw -jar <file.jar>与上面相同,但没有控制台-写入System.out的文本将丢失! JOptionPane, as explained at point 1, works for this case too (assuming system with graphical interface). 如第1点所述,JOptionPane也适用于这种情况(假设系统带有图形界面)。

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

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