Product Home








JarToExe Convert Tool Support Page

Jar2Exe V2.0 has been released at a new home:

Function: Convert JAR archive into Executive. [updated: Mar 15, 2009]

1. Java Runtime Environment for Executive

    When generated Exe runs, JRE is needed.

    The generated Exe can find JRE in many ways: "Registry", "Environment", "Configuration File". If JRE's location can be found in both Registry and configuration, the one in configuration file is used:

  1. Configuration File
    Use item "jvmdll" in configuration file to appoint JRE. [refer to: Configuration]
  2. Registry
    Install JRE normally, then generated Exe can find the JRE itself from registry.
  3. Environment Variable
    Use JAVA_HOME or JRE_HOME to tell the directory of JDK or JRE, the generated Exe can find JRE appointed itself.
  4. JRE search order
    Use item "jre_order" in configuration file to set search order. [refer to: Configuration]

2. Configure Other .jar Files Needed

    If other jar files are needed when generated Exe runs, the jar needed can be appended through environment or configuration file:

  1. Environment Variable
    Use CLASSPATH or CLASS_PATH to append jar files.
  2. Configuration File
    Use item "classpath" in configuration file to append. [refer to: Configuration]
  3. Wrap depended jars into created exe file together
    Without being extracted, depended jar files can be wrapped into generated exe file.
  4. Configuration File [new since 1.8.4]
    Use item "libs" to set a directory to contain depended jar files.

3. Set JVM Parameters

    More JVM parameters such as "-X", "-D", can be set through configuration file:

  1. Configuration File
    Use item "option" in configuration file to set. [refer to: Configuration]
  2. Configure property
    Use item "property" in configuration file to set system property.
    For example: "property a=1" equivalent to "option -Da=1"
  3. Refer to OS environment
    Use %name% to refer to OS environment in option and property.

4. The Full Path of The Generated Exe

    When generated Exe runs, the full exe path can be gotten through System Property:

String exepath = System.getProperty("");

To get the directory of exe file:

String exedir = System.getProperty("application.home");

5. About Configuration File

5.1 The Rule of Configuration File Name

    The file name: the same as the generated exe file name.
    Ext name: ".cfg" or ".config".

    Example: for exe file "test.exe", the corresponding configuration file should be "test.cfg" or "test.config". If both of these two files exist, the ".cfg" will be used only.

5.2 Use Item "jvmdll" to Appoint JRE

    In configuration file, use item "jvmdll" to appoint certain JRE.

    If the path of jvm.dll appointed starts with "/" or "Disk Letter", it is regarded as absolute path. If the path starts with "Directory", it is  regarded as relative path.

    Example: in test.cfg, if JRE is appointed with absolute path:

jvmdll C:\j2sdk1.4.2\jre\bin\server\jvm.dll

    If the directory of jre1.5.0 is copied to the same directory as the exe file, relative path should be used to appoint the JRE:

jvmdll jre1.5.0\bin\client\jvm.dll

    The method of appointing JRE with relative path, is often used in development. If the JRE is copied and shipped with exe, no other JRE is needed when runs.

5.3 Use Item "classpath" to Configure Other .jar Files Needed

    If other jar files are needed when exe runs, they can be appended by item "classpath". Use ";" to separate more than one jar files.


classpath E:\proj\classes;.;D:\lib1.jar;D:\lib2.jar

5.4 Use Item "option" to Set More JVM Parameters

    In configuration file, item "option" can be used to set JVM parameters "-X", "-D".

    Example, define a System Property: (Don't leave space around "=" or after "-D)

option -Dmyprog.settings=C:\thefile.ini

    Then, the following code can get the setting:

String where = System.getProperty("myprog.settings");

5.5 Use "jre_order" to set the JRE search order

Generated exe can find JRE from:

c - configuration
e - environments
s - SUN jre registry
i - IBM jre registry

The default order is : jre_order=csie , use different char order to set the JRE search order.

6. About Option "-target" of Javac

    When we compile java files with tool "javac.exe" of JDK, we can use option "-target" to generate class files for specific VM version. Those classes, which are generated for higher version of VM, could not be launched by lower version of VM.

    For the classes' compatibility, we should use as low "-target" version as we can. Unless that, new feature of certain version of JDK is used, or one class in certain version of JDK is used.

    Usually, we should use:

D:\>javac -target 1.2 test/

    For JDK 1.5, we should use:

D:\>javac -source 1.3 -target 1.2 test/

7. About Generated Windows NT Service

7.1 Start And Stop of The Service

    Common console program written in Java, can be run as Windows NT Service. After the task finished, that is to say, when main() returns, or System.exit() is called halfway, the service is stopped.

    If the task runs in a long time, for example sleep() or accept() is used, the service can stay "Running" status all through. The service can be stopped by the Windows Service Manager or by command "net stop".

7.2 Pause And Continue of The Service

    According to requirement, if PAUSE/CONTINUE is needed, we can implement the interface ServiceStatusHandler and let canPause() return true:

import com.regexlab.j2e.*;

public class MyHandler implements ServiceStatusHandler
    public boolean canPause()
        return true;

    Then create a MyHandler instance, pass it the ServiceStatusManager:

ServiceStatusManager.setServiceStatusHandler(new MyHandler());

    Now, the service can be paused by Windows Service Manager or "net pause" command. Also, the service status can be set by java program itself:


    These two class can be downloaded. [refer to: ServiceStatusHandler]

7.3 Installation And Uninstallation of The Service

    Generated Windows NT Service type of exe, can install/uninstall the service by itself. Use "/install" as parameter to intall. For example, [Demo 3]:

D:\>service.exe /install

    If install to auto run when system startup:

D:\>service.exe /install auto

    Use "/uninstall" to uninstall:

D:\>service.exe /uninstall

    Install service as interactive mode (since 1.8.3):

D:\>service.exe /install /interactive

7.4 Test Run of The Service Program

    In order to check the JRE and configuration, use "/test" to run the Service program as a console program:

D:\>service.exe /test

7.5 Class

    At the bottom of this page, code of interface between Java and Windows Service Manager could be downloaded. One of the classes:

public class ServiceStatusManager;

    This class is used to set Service status actively from Java:

public static void setServiceStatus(int status);

7.6 Interface

    The other one is an interface:

public interface ServiceStatusHandler;

    This interface is used: get the event when service status is changed by Windows Service Manager of Command "net stop".

package com.regexlab.j2e;

public interface ServiceStatusHandler
     * Tell the service manager whether PAUSE/CONTINUE is supported.
     * @return true means this service can be paused

    public boolean canPause();

     * Pause/continue event handle methods
     * @return must return true if pause successfully

    public boolean onPause();

     * Pause/continue event handle methods
     * @return must return true if continue successfully

    public boolean onContinue();

     * Stop service event handle method
     * @return no use

    public boolean onStop();

    Usage: implements this interface, pass the instance to ServiceStatusManager:

ServiceStatusManager.setServiceStatusHandler(new MyHandler());

    Refer to "demo 4" to create a Windows NT Service supports PAUSE/CONTINUE.

7.7 Interface Code And Doc

Download: [Interface Download] - 4kb

Document: [javadoc] © 2005 - All Rights Reserved