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/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.