I have this java program that I want to package within a jar. It compiles fine and it compiles without errors into a jar. But when I double click it, it wont start. I know most jar applications uses JFrame and that works fine. But is it possible to make it command prompt/shell based? (Like Displaying System.out.println)
Example is it possible to execute this code by double clicking a jar:
public class Hello
{
public static void main( String[] args )
{
System.out.println( "Hello, World!" );
}
}
There is no problem doing like that. But where do you expect to see the output?
If you execute from the console as java -jar my jar.jar
you will see your "Hello, World".
If you want to double-click you'll need to create a JFrame.
You can change the file association for jar files to have them open a console. (This is for Windows)
ftype jarfile
jarfile="C:\Path\To\Java\bin\javaw.exe" -jar "%1 %*"
ftype jarfile "C:\Path\To\Java\bin\java.exe" -jar "%1" %*
(You may need administrator privileges to do this).If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With