1

So i have a Javafx Maven Projekt which i run with a .bat

@echo off
set JLINK_VM_OPTIONS=
set DIR=%~dp0
"%DIR%\java" %JLINK_VM_OPTIONS% -m Main/org.openjfx.Main %*

it works but the cmd stays opend and when i close it the project closes aswell i asked the question here but i didnt got a working answer so i just ask here

btw sorry for my bad english

  • There appear to be many duplicate questions related to this. Here is a google search [batch file close site:stackoverflow.com](https://www.google.com/search?q=batch+file+close+site:stackoverflow.com&sxsrf=AOaemvLdvOOPyUpGJVZ_Arg7YFDoAE9WOQ:1637612795249&sa=X&ved=2ahUKEwjPvsKH56z0AhXJPn0KHfZzDpgQrQIoBHoECAoQBQ&biw=3440&bih=1360&dpr=1) – jewelsea Nov 22 '21 at 20:27
  • Please open a command prompt window and run `start /?` to get displayed the usage help of this internal command of `cmd.exe` which can be used to start an executable as separate process from within a batch file on which `cmd.exe` after starting the executable does not wait for self-termination before continuation of processing of the batch file. – Mofi Nov 23 '21 at 07:48
  • The entire batch file can be optimized to the single command line `@start "JavaFX Maven Project" "%~dp0java.exe" -m Main/org.openjfx.Main %*` which opens a new console window with title `JavaFX Maven Project` and showing `stdout` and `stderr` output in this console window or `@start "" "%~dp0javaw.exe" -m Main/org.openjfx.Main %*` which does not open a console window and so Java application is executed in background, except it opens itself a graphical window. – Mofi Nov 23 '21 at 07:54

2 Answers2

3

You seem to be uncertain what you need to be kept open, (the sole aim of that batch file is to keep a console window open for visual console feedback) but to answer your request, you need to run your bat file from a cmd prompt, in order to pass parameters otherwise it is mainly redundant.

@echo off
set "JLINK_VM_OPTIONS="
set "DIR=%~dp0"
start "" "%DIR%javaw" %JLINK_VM_OPTIONS% -m Main/org.openjfx.Main %*
rem See notes
rem exit

Note

javaW willstart java for windows in non console mode, thus dismissing the batch file. However if you are running from a cmd console that is a separate exit that's needed as an extra last line, so try with rem first then remove that last rem to see any difference.

If you find javaW is not suitable then remove the W at the end.

I have no idea why the source of that file was constructed in such a non windows fashion except the aim seems to be to prefix the run by clearing one and setting one preset environment value, then holding so could be reduced to

@Title "Feedback"&set "JLINK_VM_OPTIONS="&set "DIR=%~dp0"&"%DIR%java" -m Main/org.openjfx.Main %*
@echo Done&pause&exit
K J
  • 8,045
  • 3
  • 14
  • 36
0

What i understand from you is like this question How to automatically close batch program, but keep java program running? try this if it works.