I want to publish a Java GUI application on Windows 7. This application is using the Swing Toolkit and doesn't need any native code. The application is installed using an NSIS installer. I want to integrate this application into Windows 7 as good as possible. This means:
WinRun4j is an EXE file which launches the Java application. Because the application doesn't fork a new Java process Windows thinks the EXE file IS the application. So there is no problem with the taskbar. File associations works because the files can be simply associated with the EXE file.
Problems:
Launch4J creates a 32 bit EXE which launches an external Java process to start the Java application. So unlike WinRun4J it can also start a 64 bit Java.
Problems:
System.out.println
will not print to console if headerType="gui"
, regardless if application is started from console.On Windows you can simply double click the JAR file to start the application. Installed JRE doesn't matter, simply works. But...
Problems:
A simple batch file like this can be used to start the application:
@echo off start c:\windows\system32\javaw.exe -jar "c:\program files\myapp\myapp.jar" %1
A shortcut can be created for this batch file to set a custom icon.
Problems:
c:\windows\syswow64
instead and Windows doesn't redirect this call from batch files automatically. Using the JAVA_HOME
environment variable is also a no-go because Java doesn't set this automatically.Instead of using a batch file it is possible to only create a shortcut to start the application. It links to this command: c:\windows\system32\javaw.exe -jar "c:\program files\myapp\myapp.jar"
. Windows automatically redirects this call to the SysWOW64 directory if a 32 bit Java JRE is installed.
Problems:
Is there another solution which fulfills all the requirements from above? Or are there any tricks to solve the problems with the mentioned solutions?
After solving the taskbar-pinning problem using Launch4j looks like the best solution. Launch4j can easily be integrated into a Maven project (With this or this plugin), configuration is pretty easy and everything works out of the box except taskbar pinning. For taskbar-pinning the Java application must set an appModelUserId as explained in the answer to this question.
Additionally the Java application must be installed by an installer which must at least install one shortcut pointing to the EXE. This shortcut must also contain the appModelUserId. With NSIS this can be done with the WinShell plugin and a configuration like this:
CreateShortCut "$SMPROGRAMS\MyApp.lnk" \ "$INSTDIR\myapp.exe" "" "$INSTDIR\myapp.exe" 0 SW_SHOWNORMAL WinShell::SetLnkAUMI "$SMPrograms\MyApp.lnk" "MyAppModelUserId"
For some unknown reason this shortcut only has to exist. You don't have to use it. You can double-click the EXE and taskbar-pinning still works. You can even create the shortcut in some subfolder of your application folder. Taskbar-pinning stops working when the last shortcut of the EXE file is removed.
Platform(s): 64-bit Windows, Windows 10, Windows 7, Windows 8, Windows Vista, Windows XP. Browser(s) Firefox, Internet Explorer. Java version(s): 7.0, 8.0.
Try Launch4j (http://launch4j.sourceforge.net/), its a simple jar to exe wrapper (actually wrapping the jar is optional). It should solve your Icon and Taskbar requirements. Its also capable locating installed JRE's (some configurable rules). The font problem I don't quite get, Swing should automatically use fonts depending on Windows settings, unless you somehow overwrite that in the JRE options or in code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With