Collected .jar using maven. I click on the jarnik - everything works: the files are renamed, as planned. The program at the end should show a report, but the console did not open. If you run through "java -jar renamer.jar" - then yes: everything is visible.

How to make the console open automatically when opening a .jar?

  • one
    Screw the logger to the project and output it to a file, for example. The console is a special case of the “environment” in which the project is launched. If you want to go to the console, you probably need a batch file to start the application in the console with output redirection - carapuz
  • Well, this is not quite the option. The program will ask the user what file extension should be. That's why you need a console anyway. - Adeptius
  • Look towards the java.io.Console class - carapuz
  • I looked. This is a utility class for working with the console. There is no way for its independent discovery during the program. - Adeptius
  • one
    If you get along with English, read stackoverflow.com/questions/7704405/… - Roman

1 answer 1

According to the link in comments there is an instruction:

public class Main { public static void main(String[] args) throws Exception{ Console console = System.console(); if (console == null && !GraphicsEnvironment.isHeadless()) { String filename = Main.class.getProtectionDomain().getCodeSource().getLocation().toString().substring(6); Runtime.getRuntime().exec(new String[]{"cmd", "/c", "start", "cmd", "/k", "java -jar \"" + filename + "\""}); } else { ClassThatNeedToStartWithCommandPromt.main(new String[0]); } } } 

It works!