Sample usage of Commons Launcher

This documentation has been the base of the official Commons-launcher project example.


The Jakarta Commons Launcher project provides a smart way to start a Java application.

In the facts, the Commons Launcher provides a bootstrap class which starts a ant process.

This ant process :

  • makes the needed pre execution tasks : create the needed classpath, check resources, download resources ..
  • invoke a 'launcher' task which allows to start a java application


We want to start a small Main class :

 package org.kolaka.jdf.demo;
 import org.apache.commons.logging.LogFactory;
 public class Main {
   public static void main(String[] args) {

We will name it “our application” :-).

Global distribution

We planify this runtime distribution :

  • dist/demo/bin/ : the user script to start our small Main class
  • dist/demo/bin/ : contains the other files used by the script
  • dist/demo/etc/ : contains the configuration file (log4j configuration, ..)
  • dist/demo/lib/jdf2-demo.jar : contains the small Main class
  • dist/demo/lib/ : contains the needed jar files to the application
  • dist/demo/lib/launcher/ : contains the needed jar files to the commons launcher

bin directory

User script

the is the bootstrap script used by the user to start the application :

 basedir=`dirname $0`
 java -cp $basedir LauncherBootstrap -executablename `basename $0` demo

Launcher ant configuration

our launcher.xml is as simple as possible :

 <project name="JDF2 Demo Launcher" default="demo" basedir=".">
  <property name="base.dir" value="${basedir}/.."/>
  <property name="etc.dir" value="${base.dir}/etc"/>
  <property name="lib.dir" value="${base.dir}/lib"/>
  <property name="log.dir" value="${}"/>
  <path id="base.class.path">
   <pathelement path="${etc.dir}"/>
   <fileset dir="${lib.dir}" includes="*.jar"/>
  <target name="demo">
   <launch classname="org.kolaka.jdf.demo.Main">
    <classpath refid="base.class.path"/>
     <sysproperty key="log.dir" file="${log.dir}"/>

It creates the needed classpath and executes our Main class.

Other files

  • LauncherBootstrap.class, commons-launcher.jar : the needed classes the Commons Launcher
  • : the bootstrap configuration (used to find the lib/launcher files)

Build process

This is the target which prepares the dist/bin and dist/demo/lib/launcher directories (the entire ant script is included into the example sources) :

 <target name="dist.demo.bin">
  <!-- create the lib/launcher directory with the lib files provided by the commons launcher -->
  <copy todir="dist/demo/lib/launcher">
   <fileset dir="import/commons/launcher/lib">
    <include name="*.jar"/>
  <!-- copy the needed files into the bin directory -->
  <copy todir="dist/demo/bin" flatten="true">
   <!-- from the commons launcher -->
   <fileset dir="import/commons/launcher/bin">
    <include name="LauncherBootstrap.class"/>
    <include name="commons-launcher.jar"/>
   <!-- from the application sources -->
   <fileset dir="source/org/kolaka/jdf/demo">
    <include name=""/>
    <include name="launcher.xml"/>
  <!-- make executable the shell scripts -->
  <chmod perm="+x">
   <fileset dir="dist/demo/bin">
    <include name="*.sh"/>
  <!-- create a property with the path to all 'lib/launcher' files -->
  <pathconvert property="dist.demo.bin.ant.class.path" pathSep=":" >
    <fileset dir="dist/demo/lib/launcher">
     <include name="*.jar"/>
   <map from="${basedir}/dist/demo" to=".."/>
  <!-- creates the '' with this path -->	
  <propertyfile file="dist/demo/bin/">
   <entry key="ant.class.path" value="${dist.demo.bin.ant.class.path}"/>



sample_usage_of_commons_launcher.txt · Last modified: 2006/10/21 19:22 by alban
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Run by Debian Driven by DokuWiki