1

I have a simple jarfile that contains the code for my Discord bot. When I double click it, it works perfectly. I can see the bot comes online and that the javaw.exe shows up in task manager. That's the only way I can see it's working and I can't see any errors or anything. It just runs in the background. How can I make it where when I double click it, it runs just like you ran it from a batch file (just like here: Running a .jar file in a command prompt from double click)? I would like to do this without messing with batch files. I would just like one jarfile and that's it. Is there some kind of code I can use in the jarfile to make it run in the command line automatically without having to enter the command or use a batch file? Maybe if I could use Runtime.getRuntime().exec("cmd /c start java -jar <jarfile>); but somehow make it all work in one jarfile?

Output

  • to show the java output use `java.exe` instead of `javaw.exe` (the default) - this must be changed in the registry (`HKEY_CLASSES_ROOT\jarfile\Shell\Open\Command`) or using `ftype` (command line, e.g. `ftype jarfile="%JAVA_HOME%\bin\java.exe" -jar "%1" %*`; use `ftype jarfile` to see (and save) the original value!) [to avoid the console from closing, you must eventually change the command to `cmd /k start "JAVA" /b "%JAVA_HOME%\...` or similar {not sure, would have to test&try myself}] – user16320675 Jun 13 '22 at 19:04
  • oh, thanks a lot! I just changed javaw to java and it works – ThrownRedstone Jun 13 '22 at 21:21

0 Answers0