You would create a windows service and call it to start at the end of the installation on the FinishPanel.
There are a bunch of ways to do this, I for one use the postinstall.xml. In my install.xml I have something like:
<resources>
...
<res src="postinstall.xml" id="ProcessPanel.Spec.xml" />
...
</resources>
Then you need to include the ProcessPanel right after the InstallPanel like so:
<panels>
...
<panel classname="InstallPanel" id="installPanel" />
<panel classname="ProcessPanel" id="processPanel" />
...
</panels>
Now izPack would use the ProcessPanel and read your postinstall.xml and start executing those jobs in different processes.
Read more about it at:
Now, the contents of my postinstall.xml are similar to:
<processing>
<logfiledir>$INSTALL_PATH</logfiledir>
...
<job name="Create Windows Service">
<os family="windows" />
<executeclass name="com.mycomp.installer.util.GlassfishPostInstall">
<arg>GLASSFISH_JOB=createService</arg>
<arg>GLASSFISH_HOME="$INSTALL_PATH\glassfish"</arg>
<arg>adminPassFile="$INSTALL_PATH\glassfish\passfile"</arg>
<arg>adminCfgFile="$INSTALL_PATH\glassfish\glassfish\config\asenv.bat"</arg>
<arg>admin.user=${console.gfAdminName}</arg>
<arg>admin.password=${console.gfAdminPassword}</arg>
<arg>admin.port=${console.gfAdminPort}</arg>
<arg>serviceName="${console.serviceName}"</arg>
</executeclass>
</job>
...
</processing>
Then in my com.mycomp.installer.util.GlassfishPostInstall I have:
/**
* Executing a Java Class with ProcessPanel</a> of the izPack documentation, the external Java class
* must have a run() method with some parameters.<br>
* <br>
* <b>Note:</b> This is not (NOT!) the run() method from the java.lang.Runnable interface. Nor is this
* codified as an interface in the IzPack javadoc.
*
* @param handler {@link AbstractUIProcessHandler} used to emit errors.
* @param args String array with all of the specific arguments.
*/
public void run(AbstractUIProcessHandler handler, String[] args) {
Map<String,String> jobArgs = new HashMap<String,String>();
for(String arg:args) {
String[] keyProp = arg.split("=");
jobArgs.put(keyProp[0], keyProp[1]);
}
String glassfishJob = jobArgs.get("GLASSFISH_JOB");
if(glassfishJob.equalsIgnoreCase("createDomain")) {
createDomain(handler, jobArgs);
}
if(glassfishJob.equalsIgnoreCase("startDomain")) {
}
if(glassfishJob.equalsIgnoreCase("createService")) {
createService(handler, jobArgs);
}
...
}
private void createService(AbstractUIProcessHandler handler, Map<String,String> serviceProps) {
// Create Windows Service for the domain
if(gfDebug) {
StringBuilder cmd = new StringBuilder(serviceProps.get("GLASSFISH_HOME")).append("\\bin\\asadmin");
cmd.append("\n").append("create-service");
cmd.append("\n").append("--name ").append(serviceProps.get("serviceName"));
cmd.append("\n").append("--force=true");
handler.logOutput("\nCreating windows service...\n", false);
handler.logOutput(cmd.toString(), false);
}
ArrayList<String> cmdArgs = new ArrayList<String>();
cmdArgs = new ArrayList<String>();
cmdArgs.add("create-service");
cmdArgs.add("--name"); cmdArgs.add(serviceProps.get("serviceName"));
cmdArgs.add("--force=true");
gfUtil.asadmin(cmdArgs.toArray(new String[cmdArgs.size()]));
}
Above only solves the job of creating the windows service and if you don't use GlassFish you can always escpace to dos and run something like "sc.exe create ...".
To start the service at the end of the installer, I created my own panel that configures GlassFish by creating/updating my domain and deploys my webapp. At the very end it issues this:
public void startService(String name) {
List<String> params = new ArrayList<String>(Arrays.asList("cmd.exe", "/c", "sc.exe", "start", name));
String output = util.runCommand(gfBinDir, true, params.toArray(new String[params.size()]));
if(debug) {
System.out.println(output);
}
}
And immediately following my custom panel is the FinishPanel.
Hope this helps!