Reputation: 17
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
Reputation: 29670
There are at least 3 ways to execute a JAR:
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;
java -jar <file.jar>
this executes the jar opening a console - you will see what is going to System.out;
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
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