MockerTim
MockerTim

Reputation: 2483

How to start Java GUI program conveniently for the end user

The user wants to start the Java GUI application from Windows, with some amount of additional JVM parameters.
For instance:

javaw -Djava.util.logging.config.file=logging.properties -jar MyGUI.jar

If I add the above line to the batch file, the user can double-click the batch-file name.
And it's cool. But there is one annoying side effect: the batch file opens the cmd window before starting the GUI.

Is there a simple way to start the java GUI application by double-clicking the batch-file (or some other file which suits the above needs) without opening the cmd window?

Upvotes: 5

Views: 5305

Answers (4)

Allen Z.
Allen Z.

Reputation: 1588

Try

start javaw -Djava.util.logging.config.file=logging.properties -jar MyGUI.jar

You can also use scripting:

VBS:

Const HIDDEN_WINDOW = 12 

strComputer = "." 
Set objWMIService = GetObject("winmgmts:" _ 
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
Set objStartup = objWMIService.Get("Win32_ProcessStartup") 

Set objConfig = objStartup.SpawnInstance_ 
objConfig.ShowWindow = HIDDEN_WINDOW 
Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process") 
errReturn = objProcess.Create("Notepad.exe", null, objConfig, intProcessID)

JScript:

var WindowStyle_Hidden = 0
var objShell = WScript.CreateObject("WScript.Shell")
var result = objShell.Run("cmd.exe /c abc.bat", WindowStyle_Hidden)

Finally, there are general-purpose utilities you can use to hide windows, such as CMDOW and Hidden Start ($20). I have not used either myself, since start does the same thing.

Upvotes: 4

Andrew Thompson
Andrew Thompson

Reputation: 168845

The user wants to start the Java GUI application ..

The best user experience for the end user will be offered by launching the app. using Java Web Start. JWS can install desktop shortcuts and menu items to launch the app.

..from Windows..

JWS also works on OS X & *nix.

Upvotes: 3

JBert
JBert

Reputation: 3390

I see a number of ways:

  • Use a launcher as generated by Launch4J (thanks to CodeBrickie for the tip) or Install4J/Exe4J. Launch4J allows you to tweak the parameters by creating an .l4j.ini file with the same name as the exe. In case of Exe4J, extra parameters can be specified in a .vmoptions file which you drop next to the generated exe.
  • Create a Shortcut to javaw.exe, give it the icon you want, set the "Start in" field to the directory of the application and specify your parameters to javaw in the Target field.
  • Make a VB script which launches javaw. If the VBS runtime is set to use wscript, no console window will pop up.
  • If you use Java Web Start, you might want to let the user tweak the JNLP file as specified in Java Webstart with parameters.

Upvotes: 6

tobiasbayer
tobiasbayer

Reputation: 10379

Lauch4j can wrap your jar in an exe file.

Upvotes: 2

Related Questions