r/javahelp • • Feb 20 '26

Running jar with a script without terminal

We maintain a Java application which on Windows is run by a powershell script. We have to do it as the jar arguments needs to be recalculated before starting.

The issue is that running a powershell script triggers a terminal windows showing up for a second (with -WindowStyle Hidden, without this policy the terminal stays on the screen).

We managed to completely hide it by using vbs script which then runs this powershell scrip. But this has some negative side effects. Also using vbs is currently deprecated.

Is there a better way to run a jar with dynamic arguments without a terminal window showing up at all? We try to find a way to do it without vbs involvement.

Edit: it seems that using conhost was the solution i was looking for.

In a shortcut i used conhost --headless powershell -File script.ps1 ...

10 Upvotes

27 comments sorted by

View all comments

Show parent comment

1

u/JackNotOLantern Feb 20 '26

The script is run by a shortcut and you can click a file and use "open with... <shortcut name>" (we have an installer which sets up that). You can also set a file type to be opened by default by it and double clicking the file will start the application with the file name as the argument.

This is how Windows handles "open with..." option. If the shortcut was just triggering "javaw.exe -jar <jar name>" it would pass the arguments directly to the jar. To process the arguments in any way i have to use some kind of scrip or other program.

Currently the shortcut runs vbs script which runs ps1 script which runs the jar.

1

u/Beautiful-Maybe-7473 Feb 20 '26

OK! That makes sense!

I think you can address this encoding issue by changing the Windows system locale; that may be another option for you. It may not be practicable in your workplace, but if you can do this, it should mean you could dispense with a script altogether. That's in Windows region settings: "Use Unicode UTF-8 for worldwide language support".

Alternatively, there are custom Java launchers which should also mitigate the problem, such as Launch4J which would be in some ways more of a generic solution than a custom script https://launch4j.sourceforge.net/