I have always been a big proponent of distributing program using a zip file. This is quite easy for java, especially when you want integrate (a specific version of) the jre.
However you need a batch file which runs in a console to start the program. In windows this console will stay on screen, which is (to say the least) not so pretty.
As a solution, I wanted to have a simple program which allows the java program to be started by just running a small executable. In the process a couple of other features have been added to make it all more powerful.
This little program (with sources, written in Delphi) can be found here.
The program is controlled by a .ini file. You can rename the jrun.exe file to anything you want, and it will use an .ini file with the same name to read the settings which are used to start the java program. In this file, you could use several sections, when a parameter is given to the program, it will first look in the section with the given name and then continue by looking in the section named “default”. You have the following options.
- name of main class (otherwise it would be problematic)
- directory where the jre can be found (relative to current directory, where is normally where the .ini file is located)
- java parameters, like properties, memory etc, for example “-Ddebug=true -Xmx256m”
- whether the program should be restarted if it exits (for example if the jre crashes or the program exists)
- a splash image which should be displayed while starting
- the parts of the classpath, these can be given as a reference to a jar file, a directory which is added itself, a directory where all the jar and zip files are added from
When indicating what should be added to the classpath, you can also specify a URL where the jar file can be found. This allows installations where the program itself is downloaded from the server. This can greatly simplify installation.
When adding jar files to the classpath, you can choose whether the files should be copied to a temporary directory before use or not. The default behaviour is to copy the files. This can be a big advantage as it allows changing the jar files while the program is running (the locks are on the copies). That way, the update does not take longer (for the user) than a restart of the program.
More details about the use can be found in the default .ini file in the jrun.zip file.