WinRun4j
Configurable Java Launcher for Windows
About
WinRun4j is a java launcher for windows. It is an alternative to javaw.exe and provides the following benefits:
  • Uses an INI file for specifying classpath, main class, vm args, program args.
  • Custom executable name that appears in task manager.
  • Additional JVM args for more flexible memory use.
  • Built-in icon replacer for custom icon.
  • Pre-JVM splash screen with auto-hide.
  • DDE implementation for file assocations.
  • Windows NT Service wrapper.
  • Windows EventLog API
  • Console version
  • JNI library for INI access, splash screen, logger, registry, shell.
  • Support for 64-bit JVM.

WinRun4J is licensed under the Common Public License (CPL).

Download
The latest download is available from the Project Page.
Usage
The launcher is designed to be used as follows:
  1. Copy WinRun4J.exe to [YourApp].exe
  2. Create [YourApp].ini (in the same directory)
  3. Customize [YourApp].ini (see the table below for information)
  4. Create [YourApp].ico (in the same directory)
  5. Run [YourApp].exe --WinRun4J:SetIcon (this will inject your icon into the executable).
  6. Launch [YourApp].exe
The INI file accepts the following settings:

KeyDescription
working.directory This will be the current directory for the app. It can be relative to your executable.
classpath.1, classpath.2, ..., classpath.n Classpath entries. These will be relative to the working directory above. They can be wildcards (eg. *.jar)
main.class This is the java class that will be run
vmarg.1, vmarg.2, ..., vmarg.n Java VM args. These will be passed on to the VM.
vm.version.max The maximum allowed version (1.0, 1.1, 1.2, 1.3, 1.4, 1.5).
vm.version.min The minimum allowed version (1.0, 1.1, 1.2, 1.3, 1.4, 1.5).
vm.version Specify an exact version to use (eg. 1.5.0_07).
vm.location Specify the location of the JVM dll you want to use. This is useful when you package your own JRE with your app.
vm.heapsize.max.percent Specify a proportion of the available physical memory to use (ie. relates to -Xmx arg). For example, vm.heapsize.max.percent=75. Note that this will use the maximum memory possible.
vm.heapsize.min.percent Specify a proportion of the available physical memory to use as the minimum starting heap size (ie. relates to -Xms arg).
vm.heapsize.preferred Specify a preferred amount (in MB) for the heap size (ie. relates to -Xmx arg). If this amount is not available it will use the maximum amount possible given the physical memory available.
arg.1, arg.2, ..., arg.n Program arguments. These will be sent before any command line arguments.
log Standard out and error streams will be redirected to this file (including launcher messages).
log.level Specify the logging level. One of "info", "warning", "error", "none". Default is "error".
splash.image The name of the splash image file to display (This can be gif, jpg or bmp). This will auto-hide itself when it detects the first application window.
splash.autohide A flag to disable the splash screen autohide feature ("true").
dde.enabled This flag needs to be set to "true" to enable DDE.
dde.class Optional flag to send execute commands to your class.
dde.server.name, dde.topic, dde.window.class Override the DDE server name, topic and window class.
single.instance This will detect another instance of the application running and will shutdown if one is found.
It takes the following options:
  • "process", this will simply detect if a process for the same executable is present and shutdown.
  • "window", this will detect if a process for the same executable is present and if there is a visible window - if this is the case it will set the window to the front and then shutdown.
  • "dde", this will simply detect if a process for the same executable and if dde is enabled it will fire a dde activation call (and then shutdown), which can be picked up by the other process. If dde is not enabled it will simply defer to the "window" method.
service.class This is the java class that will be run (for a service)
service.id This is the ID of the service (used for registration)
service.startup Can be one of "auto", "boot", "demand", "disabled", "system". The default is "demand"
service.dependency.1, service.dependency.2, .... Specifies a set of services that this service depends on.
service.loadordergroup Specifies the service's load order group.
service.user Specifies the account to run the service under.
service.password Specifies the password for the user account.
Error Messages
Error messages emitted by the launcher can be customized via the INI file. These can be placed in an "[ErrorMessages]" section:

KeyDescription
java.not.found This message will be displayed as a message box popup when the launcher cannot find an appropriate JVM to load.
java.failed This message will be displayed as a message box popup when the JVM fails to startup, for example if invalid VM args are entered in the INI file


An example is as follows:
[ErrorMessages]
java.not.found=A suitable version of Java could not be found on your system. Please contact VendorX.
java.failed=Java failed to startup successfully. Please contact VendorX.
		
JNI Library
The javadoc for the JNI library can be found here.
Examples
An example INI file (included in the download) is:
classpath.1=*.jar
main.class=org.boris.winrun4j.WinRunTest
An example INI file to run eclipse is:
working.directory=.
main.class=org.eclipse.equinox.launcher.Main
classpath.1=plugins\org.eclipse.equinox.launcher*
arg.1=-showsplash				
vm.heapsize.percent=80
Eclipse DDE Example

The download includes an alternative launcher for Eclipse that enables DDE. This allows the user to double-click on a java file in Windows explorer and have the file open in the currently opened workspace.

To setup this example:

  1. In your eclipse directory rename eclipse.exe to eclipse.exe.old and rename eclipse.ini to eclipse.ini.old.
  2. Copy WinRun4J.exe, EcliseDDE.jar, eclipse.ico and eclipse.ini from to downloaded zip file to your eclipse directory.
  3. Rename WinRun4J.exe to eclipse.exe.
  4. Run eclipse.exe --WinRun4J:SetIcon. This will change the exectable icon to the eclipse icon.
  5. Run eclipse.exe --WinRun4J:RegisterFileAssociations. This will register java files to be associated with eclipse.
You should now be able to double-click on java files in Windows.

The following shows the INI file setup:

working.directory=.
main.class=org.boris.winrun4j.EclipseDDE
classpath.1=EclipseDDE.jar
classpath.2=plugins\org.eclipse.equinox.launcher*
vmarg.1=-Xmx512M
vmarg.2=-XX:MaxPermSpace=256M
arg.1=-showsplash
dde.enabled=true
dde.class=org.boris.winrun4j.EclipseDDE

[FileAssociations]
file.1.extension=.java
file.1.name=EclipseJavaFile
file.1.description=Java Source File
Service Example

The download contains a simple example of a windows service. Its only function is to log to the Windows Event Log every five minutes. To run the example:

  1. Create a test directory C:/test.
  2. Copy WinRun4Jc.exe to C:/test and rename to service.exe.
  3. Copy service.ini to C:/test.
  4. Copy WinRun4JTest.jar to C:/test.
  5. Run service.exe --WinRun4J:RegisterService.
  6. To start/stop the service use the control panel services console (The service name will be "WinRun4J Test Service")
  7. To unregister run service.exe --WinRun4J:UnregisterService.

The following shows the included example of a basic Service implementation.

package org.boris.winrun4j.test;

import org.boris.winrun4j.*;

public class ServiceTest implements Service {
    private int returnCode = 0;
    private boolean shutdown = false;
    
    public int doRequest(int request) throws ServiceException {
        switch(request) {
        case SERVICE_CONTROL_SHUTDOWN:
        case SERVICE_CONTROL_STOP:
            shutdown = true;
            break;
        }
        return 0;
    }

    public int getControlsAccepted() {
        return SERVICE_ACCEPT_SHUTDOWN | SERVICE_ACCEPT_STOP;
    }

    public String getName() {
        return "WinRun4J Test Service";
    }

    public String getDescription() {
        return "An example service using WinRun4J.";
    }

    public int main(String[] args) throws ServiceException {
        int count = 0;
        while(!shutdown) {
            try {
                Thread.sleep(60000);
            } catch (InterruptedException e) {
            }
            
            if(++count % 5 == 0) 
                EventLog.report("WinRun4J Test Service", EventLog.INFORMATION, "Ping");
        }
        
        return returnCode;
    }
}
The INI file for this service looks like this:
service.class=org.boris.winrun4j.test.ServiceTest
service.id=ServiceTest
classpath.1=*.jar

vmarg.1=-Xdebug
vmarg.2=-Xnoagent
vmarg.3=-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n
Change History
V0.1.10
  • Improvements to DDE (plus fix for Eclipse launcher).
  • Extra checks for Sun VM runtime library bugs.
  • Fixes for icon setting race condition.
V0.1.9
  • Added single.instance feature.
  • Extra features added to service registration.
V0.1.8
  • Fixes for large classpath logging.
  • Improved logging/diagnostics.
V0.1.7
  • Fixes for 64-bit version.
V0.1.6
  • Fix for console attach on Windows 2000.
V0.1.5
  • Fix to include resource files in CPP source file package.
V0.1.4
  • More fixes for DDE execution on startup.
  • Added support for IBM JRE.
V0.1.3
  • Fixes for DDE execution on startup.
V0.1.2
  • Improvements to examples.
  • Experimental 64bit build.
  • Fix to CPP source files in package.
V0.1.1
  • Fixed bug in console logger.
V0.1.0
  • Added DDE for file assocations (with Eclipse java file association example).
  • Added Service wrapper.
  • Added Event Log API.
  • Added Registry API.
  • Reduced EXE size (using wcrt).
  • Added console version.
  • Environment variables can be used in INI file (eg. %TEMP%).
  • Fix for "." in classpath
  • Improved classpath handling with nested wildcards
  • Flag to disable splash screen autohide
V0.0.5
  • Added vm.location key.
V0.0.4
  • Fixes splash screen window not being destroyed.
V0.0.3
  • Added JNI access to INI file contents.
  • Added splash screen with auto-hide.
  • Added JNI access to the splash screen.
V0.0.2
  • Added VM version arguments to allow specification of minimum version, maximum version or exact version.
  • Add VM proportional heap size argument.
  • Added logging level.
  • Improved icon changer (no rename required).
V0.0.1
  • Initial release.
Contributors
  • Peter Smith
  • Karl von Randow
  • AquaFold, launcher used in Aqua Data Studio.
  • Frederic Canut