My favorites | Sign in
Project Home Downloads Wiki Issues Source
An easy approach for maintaining launching scripts
JAVA, Launcher, script
Updated Nov 25, 2010 by

It is common approach to provide os specific scripts(bat/sh files) to launch java application.
We populate classpath, system properties etc, in bat/sh file and launch java process.
Problem with this approach is, classpath etc are inlined in both bat and sh files.
You need to ensure that classpath etc in both bat/sh files are always in sync. This is a tedious task;

There any many products which help you to create native launchers for java application. These products
take classpath etc as input and generate os specific launchers. Problem with this approach is,
If the end user wants to tweak some of those parameters like heap-size add database specific jars to classpath.
Because classpath etc informations is embedded inside generated native launcher, it is not possible to change them;

JLibs comes with JLaunch scripts which help java developers to overcome these problems.

you will find two script files:

these script files take a conf file as argument. This conf file contains all the information like classpath, system properties etc.

to launch your java app on windows:

path/to/jlauncher.bat path/to/myapp.conf

to launch the same app on nix:

path/to/ path/to/myapp.conf

the working directory of java process launched will the directory in which conf file is present.

any additional arguments after conf file are passed as main class arguments

path/to/ path/to/myapp.conf arg1 arg2 arg3

let us see a sample conf file:





# use mx4j mbean server

# logging properties



The conf file is composed of following sections:

  • Each section is followed by its configuration. You can omit the sections you don't need.
  • the order of sections in conf file is not significant.
  • A line starting with # is treated as comment.
  • Any empty lines in conf file are ignored.
  • Any line which is not in section is ignored (i.e lines before first section are ignored)
  • wildcards are not supported. i,e. you shouldn't write lib/*.jar
  • Environment variables can be used in conf file. But it makes your conf file no more platform independent.

Rather than asking end user to type " myapp.conf" to launch your java app, you can create simple wrappers as explained below: and xsd-viewer.bat from jlibs which launch xsd-viewer swing application. is a shell script cum conf file.
xsd-viewer.bat passes as conf file to jlaunch.bat; i.e you should ship along with xsd-viewer.bat for windows;

Your comments are appreciated;

Sign in to add a comment
Powered by Google Project Hosting