Bug 22553

Summary: <java> taks: make java return after starting a service thread
Product: Ant Reporter: skripi <skripi>
Component: Core tasksAssignee: Ant Notifications List <notifications>
Status: RESOLVED DUPLICATE    
Severity: enhancement CC: skripi
Priority: P3    
Version: unspecified   
Target Milestone: 1.6   
Hardware: All   
OS: All   

Description skripi 2003-08-19 13:14:53 UTC
Hi,

(this may be a duplicate Enhancement request, but i was unable to master the 
query interface... :().

I was wondering if it would be possible to make the java task return (by some 
option e.g. service="true"), if i start a java service thread (e.g. tomcat).

Most of the runtime scripts suplied with tomcat do determin the classpath setup 
Variables and start a javacomand with certain argements. I belief all of them 
could live inside a single build.xml file.

I tried to acomplish this, which did almost work, but the <java> task never 
returned and kept waiting until the server was actually shut down. I belief (!)
it would be easy to add this option to further releases of ant.

--------------- sample build.xml file for tomcat --------------
<project name="tomcat" default="usage" basedir=".">
    <description>
        Tomcat startup and shut script for ant
    </description>
    <!--
    (c) 2003 Jens Skripczynski

    This script must be placed in the root directory of the tomcat
    installation. To run this script type 'ant -f tomcat.xml option' where
    option can be one of the following value 'start', 'stop' and 'restart'.

    -->

   <!-- set global properties for this script -->

   <!-- assume the file is in the root directory of tomcat -->
  <property name="catalina-base" location="."/>
  <property name="catalina-home" location="."/>
  <property name="catalina-temp" location="./temp"/>
  <property name="java.endorsed.dirs" location="common/endorsed"/>

  <property name="tomcat-bootstrap"
            value="org.apache.catalina.startup.Bootstrap"/>

   <path id="tomcat-4.1-cp">
      <pathelement path="${java.class.path}"/>
      <pathelement path="${JAVA_HOME}/lib/tools.jar"/>
      <pathelement path="bin/bootstrap.jar"/>
   </path>

  <target name="usage"
        description="displays script usage" >
        <echo> Usage: ant -f tomcat.xml start|stop|restart </echo>
    </target>

    <target name="tomcat" description="executes tomcat with ${param}" >
       <echo> Executing tomcat with: ${param} </echo>
     <java fork="yes"
        classname="${tomcat-bootstrap}">
           <arg value="${param}" />
       <sysproperty key="catalina.base"      value="${catalina-home}" />
       <sysproperty key="catalina.home"      value="${catalina-home}" />
       <sysproperty key="java.io.tmpdir"     value="${catalina-temp}" />
       <sysproperty key="java.endorsed.dirs" value="${java.endorsed.dirs}" />
       <classpath refid="tomcat-4.1-cp" />
    </java>
 </target>

  <target name="start"
     description="starts the tomcat server" >
     <antcall target="tomcat">
        <param name="param" value="start"/>
     </antcall>
    <echo> Started tomcat server </echo>
  </target>

  <target name="stop"
        description="starts the tomcat server" >
     <antcall target="tomcat">
        <param name="param" value="stop"/>
     </antcall>
    <echo> Stopped tomcat server. </echo>
  </target>
  <target name="stop"
        description="starts the tomcat server" >
     <antcall target="tomcat">
        <param name="param" value="stop"/>
     </antcall>
    <echo> Stopped tomcat server. </echo>
  </target>
</project>
Comment 1 Antoine Levy-Lambert 2003-08-19 19:07:55 UTC
fixed with new attribute spawn in ant 1.6

*** This bug has been marked as a duplicate of 5907 ***