Murtaza Ali
Murtaza Ali

Reputation: 17

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

when i tried to export it into runnable it does not execute. i am using Eclipse for java.

My code is

package hello;

public class HelloWorld {

public static void main(String[] args) {


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

   }

}

Upvotes: 0

Views: 179

Answers (2)

user85421
user85421

Reputation: 29670

There are at least 3 ways to execute a 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, e.g. Windows) - this does not open a console and you would not see any output going to System.out, like in your code.

    In that case you could add a statement as 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;

  3. javaw -jar <file.jar> same as above but without console - text written to System.out will be lost! JOptionPane, as explained at point 1, works for this case too (assuming system with graphical interface).

Upvotes: 1

cse
cse

Reputation: 4104

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. Check it with some pause statement. May be you can use Thread.sleep(x) for wait.

Upvotes: 1

Related Questions