Evan
Evan

Reputation: 714

How to run jlink-generated Java runtime image without CMD window?

I've created Java runtime image for a simple OpenJFX application. In order to run this app, jlink auto-generated two lauch scripts under %image_path%/bin directory. This how it looks like (the one for Windows):

@echo off
set JLINK_VM_OPTIONS=
set DIR=%~dp0
"%DIR%\java" %JLINK_VM_OPTIONS% -m app/com.package.Launcher %*

Obviously, when I run this batch file it opens new shell window, which is not what I want to. I've tried all common approaches: use javaw instead of java, run script via start command etc. Nothing works.

Is it possible to avoid shell window or somehow create native launcher?

Upvotes: 1

Views: 3131

Answers (4)

yanki Boy
yanki Boy

Reputation: 1

It's very easy to run a bat file without showing the cmd window. you just need to create VBS file to run bat file with the following cmd

Set WshShell = CreateObject("WScript.Shell") 
WshShell.Run chr(34) & ".\bin\launcher.bat" & Chr(34), 0
Set WshShell = Nothing

Save cmd in the file out of the bin folder with any name like Launcher.vbs.

Upvotes: 0

mipa
mipa

Reputation: 10640

What you´d like to achieve is very well possible. It is actually even quite easy and I use this every day. There already is an early access build of jpackage available here: http://jdk.java.net/jpackage/ Creating executables works already nicely (I use it on Mac and Windows). Only creating installers is still a bit problematic.

Upvotes: 1

Matt Harrison
Matt Harrison

Reputation: 358

This looks to be possible using vbscript. If you put the following script into a .vbs file next to the launcher.bat file (or whatever the name of the batch file is):

CreateObject("Wscript.Shell").Run CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName) & "\launcher.bat " & WScript.Arguments(0) & " > " & CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName) & "\launch-log.log", 0, False

This runs the batch file in the same directory, and also redirects stdout to a log file.

Upvotes: 0

Evan
Evan

Reputation: 714

Ok, I've figured out it's not posiible to eliminite shell window completely. In the best scenario it's just flickers for ~1sec. This is how it can be achieved:

@echo off
set JLINK_VM_OPTIONS=
set DIR=%~dp0
start "" "%DIR%\javaw" %JLINK_VM_OPTIONS% -m app/com.package.Launcher %* && exit 0

There is a feature request about native laucher implementation but it's not discussed actively.

Nonetheless I've solved the problem. There is "Batch to EXE Converter" tool. It can generate executable (basically the same batch file) which can run your app silently.

Upvotes: 2

Related Questions