Here's what I wrote a few days ago. It basically invokes the main method
of Bootstrap class found in the bin directory. I plan to use the
imbedded version over the coming weekend (I can give it to if you are
interested) so that I can configure catalina (Tomcat-4.x.x) inside the
build file. 

It starts tomcat on a separate thread, you can easily modify this. I
tried using the java task to start catalina but the bootstrap failed to
load the jar files required to run it. Funny thing is that it works fine
when I'm shutting it down.



On Tue, 2002-08-20 at 20:57, Eric Wright wrote:
> Good afternoon, 
> 
> I was wondering if there is a task that will allow me to launch an instance of
> Tomcat similar to wlrun. 
> 
> Thank you
> 
> Eric W.
> 
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

package pali.ant;

import org.apache.catalina.connector.http.HttpConnector;
import org.apache.catalina.LifecycleListener;
import org.apache.catalina.LifecycleEvent;
import org.apache.catalina.Container;
import org.apache.catalina.startup.Embedded;
import org.apache.catalina.logger.FileLogger;
import org.apache.catalina.Logger;
import org.apache.catalina.Connector;
import org.apache.catalina.Context;
import org.apache.catalina.Engine;
import org.apache.catalina.Host;

import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildException;

import java.io.IOException;
import java.net.InetAddress;
import java.util.ArrayList;

//Alpha hacks...
import org.apache.catalina.startup.Bootstrap;

public class StartTomcatTask extends Task implements Runnable {

  ArrayList args = new ArrayList();
  String confDIR = "conf";
  String home ="tomcat";
  boolean nonaming = false;
  boolean debug = false;

  public void setConfig(String file) {
    this.confDIR = file;
    args.add("-config");
    args.add(file);
  }

  public void setHome(String home) {
    this.home = home;
  }

  public void setDebug(boolean debug) {
    this.debug = debug;
  }

  public void setNonaming(boolean debug) {
    this.nonaming = nonaming;
  }

  public void execute() throws BuildException {
    try {	
      Thread thread = new Thread(this);
      thread.setDaemon(true);
      thread.start();
    } catch (Exception ex) {
      throw new BuildException(ex);
    }
  }

  public void run() {
    try {
      String[] args = { "-config", confDIR, "start" };
      System.setProperty("catalina.home", home);
      Bootstrap.main(args);
    } catch (Exception ex) {
      super.log(ex.getMessage(), 1);
    }
  }
}

Attachment: StartTomcatTask.class
Description: application/java-byte-code

<?xml version="1.0" encoding="UTF-8"?>

<project name="Pali" default="start" basedir=".">

  <property name="fullname" value="Pali Newsletter Server."/>
  <property name="version" value="0.1-dev"/>

  <property name="catalina.home" value="/home/themba/pali/tomcat"/>
  <property name="catalina.base" value="${catalina.home}"/>
  <property name="java.io.tmpdir" value="$catalina.home/temp}"/>
  <property name="xindice" value="xindice"/>

  <taskdef name="tomcat" classname="pali.ant.StartTomcatTask"/>

  <target name="init">
  	<echo message="Welcome to the ${fullname} ${version}"/>
    <echo message="Please note that this is development software"/>
    <echo message="and we cannot guarantee its stability."/>
	  <echo message="---------------------------------------------"/>
    <echo message="Using catalina.home ${catalina.home}"/>
  </target>
  
  <target name="start" depends="init">
    <echo message="Starting a tomcat instance."/>
    <tomcat config="conf/server.xml" home="tomcat"/>
    <!--
    <java classname="org.apache.catalina.startup.Bootstrap">
      <arg value="-config"/>
      <arg value="${catalina.home}/conf"/>
      <arg value="-debug"/>
      <arg value="start"/>
      <classpath>
        <pathelement location="${catalina.home}/bin/bootstrap.jar"/>
        <pathelement location="${catalina.home}/server/lib/catalina.jar"/>
      </classpath>
    </java>
    -->
    <sleep minutes="5"/>
    <java classname="org.apache.catalina.startup.Bootstrap">
      <arg value="-config"/>
      <arg value="${catalina.home}/conf/server.xml"/>
      <arg value="stop"/>
      <classpath>
        <pathelement location="${catalina.home}/bin/bootstrap.jar"/>
        <!--
        <pathelement location="${catalina.home}/server/lib/catalina.jar"/>
        -->
      </classpath>
    </java>
  </target>
</project>

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to