r/javahelp • u/JackNotOLantern • 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 ...
View all comments
Show parent comment
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/