System.out.println in jar

2019-06-26 12:54发布

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!" );
  }
}

7条回答
地球回转人心会变
2楼-- · 2019-06-26 13:53

You can change the file association for jar files to have them open a console. (This is for Windows)

  • Open Command Processor
  • Type ftype jarfile
  • You will get something like:

jarfile="C:\Path\To\Java\bin\javaw.exe" -jar "%1 %*"

  • Enter ftype jarfile "C:\Path\To\Java\bin\java.exe" -jar "%1" %* (You may need administrator privileges to do this).
查看更多
登录 后发表回答