The Commons-launcher project provides a smart way to start a Java application. In the facts, the CommonsLauncher provides a bootstrap class which starts a ant process.
This ant process :
We want to start a small Main class :
package org.apache.launcher.example;
import org.apache.commons.logging.LogFactory;
public class Main {
public static void main(String[] args) {
LogFactory.getLog(Main.class).info("start");
}
}
This runtime distribution includes:
User script
The demo.(sh/bat) is the bootstrap script used by the user to start the application:
java -cp . LauncherBootstrap -executablename launcher-demo demo
Launcher ant configuration
Our launcher.xml is as simple as possible :
<project name="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="${base.dir}/log"/>
<path id="base.class.path">
<pathelement path="${etc.dir}"/>
<fileset dir="${lib.dir}" includes="*.jar"/>
</path>
<target name="demo">
<mkdir dir="${log.dir}" />
<launch classname="org.apache.launcher.example.Main">
<classpath refid="base.class.path"/>
<syspropertyset>
<sysproperty key="log.dir" file="${log.dir}"/>
</syspropertyset>
</launch>
</target>
</project>
Other files