You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "Jan C." <ch...@gmail.com> on 2011/01/19 10:17:18 UTC

Terminate an Ant target

Hello,
I use ant to run some JUnit test. My JUnit test need a http server so
I also start one in my test:

<target name="mytest" depends="build">
<parallel failonany="true" >
    <sequential>
      <!-- Start HTTP server here -->
       <java fork="yes"
classname="org.apache.axis2.transport.http.SimpleHTTPServer" >
          ...
    </sequential>
    <sequential>
      <!-- Run JUnit tests here-->
       <junit> ...
    </sequential>
</parallel>
</target>


The problem I have is that the SimpleHTTPServer is running forever so
even when my JUnit test finish successfully, the ant target does not
terminate. I can only terminate it using Ctrl+C. Since I want this
target to be automated, I would like to find a way to "successfully"
stop the ant target when the junit task finishes.

Any ideas ?

cheers,
Jan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Terminate an Ant target

Posted by Michael Ludwig <mi...@gmx.de>.
Jan C. schrieb am 19.01.2011 um 14:00 (+0100):
> what I meant is that I don't start the server from my java class so I
> can't call
> > embedded.destroy();

Which is why I tried to refer you to the <script> task …

> > You probably just need to become even more programmatical. ;-)
> >
> >> > Don't know if you'll have to resort to the <script> task to
> >> > implement that.

;-)

-- 
Michael Ludwig

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Terminate an Ant target

Posted by "Jan C." <ch...@gmail.com>.
what I meant is that I don't start the server from my java class so I can't call
> embedded.destroy();

;)


On Wed, Jan 19, 2011 at 12:31 PM, Michael Ludwig <mi...@gmx.de> wrote:
> Jan C. schrieb am 19.01.2011 um 11:26 (+0100):
>> I'm not starting the SimpleHTTPServer programmatically so I
>> don't have any reference to the instance.
>
> You don't have a reference, but you do start the server
> programmatically. ;-)
>
>> >> <target name="mytest" depends="build">
>> >> <parallel failonany="true" >
>> >>     <sequential>
>> >>       <!-- Start HTTP server here -->
>> >>        <java fork="yes"
>> >> classname="org.apache.axis2.transport.http.SimpleHTTPServer" >
>
> You probably just need to become even more programmatical. ;-)
>
>> > Don't know if you'll have to resort to the <script> task to
>> > implement that.
>
> --
> Michael Ludwig
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Terminate an Ant target

Posted by Michael Ludwig <mi...@gmx.de>.
Jan C. schrieb am 19.01.2011 um 11:26 (+0100):
> I'm not starting the SimpleHTTPServer programmatically so I
> don't have any reference to the instance.

You don't have a reference, but you do start the server
programmatically. ;-)

> >> <target name="mytest" depends="build">
> >> <parallel failonany="true" >
> >>     <sequential>
> >>       <!-- Start HTTP server here -->
> >>        <java fork="yes"
> >> classname="org.apache.axis2.transport.http.SimpleHTTPServer" >

You probably just need to become even more programmatical. ;-)

> > Don't know if you'll have to resort to the <script> task to
> > implement that.

-- 
Michael Ludwig

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Terminate an Ant target

Posted by "Jan C." <ch...@gmail.com>.
Hi,
I'm not starting the SimpleHTTPServer programmatically so I don't have
any reference to the instance.

cheers,
Jan

On Wed, Jan 19, 2011 at 11:21 AM, Michael Ludwig <mi...@gmx.de> wrote:
> Jan C. schrieb am 19.01.2011 um 10:17 (+0100):
>> My JUnit test need a http server so I also start one in my test:
>>
>> <target name="mytest" depends="build">
>> <parallel failonany="true" >
>>     <sequential>
>>       <!-- Start HTTP server here -->
>>        <java fork="yes"
>> classname="org.apache.axis2.transport.http.SimpleHTTPServer" >
>>           ...
>>     </sequential>
>>     <sequential>
>>       <!-- Run JUnit tests here-->
>>        <junit> ...
>>     </sequential>
>> </parallel>
>> </target>
>>
>>
>> The problem I have is that the SimpleHTTPServer is running forever so
>> even when my JUnit test finish successfully, the ant target does not
>> terminate. I can only terminate it using Ctrl+C. Since I want this
>> target to be automated, I would like to find a way to "successfully"
>> stop the ant target when the junit task finishes.
>
> You could try calling destroy() on the instance as in this example:
>
> http://www.devdaily.com/java/jwarehouse/axis2-1.3/modules/kernel/src/org/apache/axis2/transport/http/SimpleHTTPServer.java.shtml
>
>    if (embedded != null) { // this is the SimpleHTTPServer instance
>        try {
>            embedded.destroy();
>        } catch (Exception e) {
>            log.error(e.getMessage(), e);
>        }
>    }
>
> Don't know if you'll have to resort to the <script> task to implement
> that.
> --
> Michael Ludwig
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Terminate an Ant target

Posted by Michael Ludwig <mi...@gmx.de>.
Jan C. schrieb am 19.01.2011 um 10:17 (+0100):
> My JUnit test need a http server so I also start one in my test:
> 
> <target name="mytest" depends="build">
> <parallel failonany="true" >
>     <sequential>
>       <!-- Start HTTP server here -->
>        <java fork="yes"
> classname="org.apache.axis2.transport.http.SimpleHTTPServer" >
>           ...
>     </sequential>
>     <sequential>
>       <!-- Run JUnit tests here-->
>        <junit> ...
>     </sequential>
> </parallel>
> </target>
> 
> 
> The problem I have is that the SimpleHTTPServer is running forever so
> even when my JUnit test finish successfully, the ant target does not
> terminate. I can only terminate it using Ctrl+C. Since I want this
> target to be automated, I would like to find a way to "successfully"
> stop the ant target when the junit task finishes.

You could try calling destroy() on the instance as in this example:

http://www.devdaily.com/java/jwarehouse/axis2-1.3/modules/kernel/src/org/apache/axis2/transport/http/SimpleHTTPServer.java.shtml

    if (embedded != null) { // this is the SimpleHTTPServer instance
        try {
            embedded.destroy();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }

Don't know if you'll have to resort to the <script> task to implement
that.
-- 
Michael Ludwig

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Terminate an Ant target

Posted by "Jan C." <ch...@gmail.com>.
ok thanks for the hint

On Wed, Jan 19, 2011 at 9:22 PM, Antoine Levy-Lambert <an...@gmx.de> wrote:
> Hi,
>
> on the JUnit leg of your parallel invocation, you need to use a script to
> kill your http server. Depending on your operating system you could use
> pskill from sysinternals (Windows) or just kill (UNIX).
>
> To find out the process number, there is a tool called pv.exe from teamcti
> which can list Windows processes with the full command line, provided the
> proper format option.
>
> I use pv -e -o"%i %r %d %l"
>
> With this pv command you can find which process is the axis process to have
> the id to be able to selectively kill it.
>
> On UNIX (Solaris) you can achieve the same using /usr/ucb/ps -auxww . Not
> sure other UNIXes.
>
> Regards,
>
> Antoine
>
> On 1/19/2011 4:17 AM, Jan C. wrote:
>>
>> Hello,
>> I use ant to run some JUnit test. My JUnit test need a http server so
>> I also start one in my test:
>>
>> <target name="mytest" depends="build">
>> <parallel failonany="true">
>>     <sequential>
>>       <!-- Start HTTP server here -->
>>        <java fork="yes"
>> classname="org.apache.axis2.transport.http.SimpleHTTPServer">
>>           ...
>>     </sequential>
>>     <sequential>
>>       <!-- Run JUnit tests here-->
>>        <junit>  ...
>>     </sequential>
>> </parallel>
>> </target>
>>
>>
>> The problem I have is that the SimpleHTTPServer is running forever so
>> even when my JUnit test finish successfully, the ant target does not
>> terminate. I can only terminate it using Ctrl+C. Since I want this
>> target to be automated, I would like to find a way to "successfully"
>> stop the ant target when the junit task finishes.
>>
>> Any ideas ?
>>
>> cheers,
>> Jan
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Terminate an Ant target

Posted by Michael Ludwig <mi...@gmx.de>.
Antoine Levy-Lambert schrieb am 19.01.2011 um 15:22 (-0500):
> 
> To find out the process number, there is a tool called pv.exe from
> teamcti which can list Windows processes with the full command line,
> provided the proper format option.

Great tool - thanks for sharing this information.

-- 
Michael Ludwig

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Terminate an Ant target

Posted by Antoine Levy-Lambert <an...@gmx.de>.
Hi,

on the JUnit leg of your parallel invocation, you need to use a script 
to kill your http server. Depending on your operating system you could 
use pskill from sysinternals (Windows) or just kill (UNIX).

To find out the process number, there is a tool called pv.exe from 
teamcti which can list Windows processes with the full command line, 
provided the proper format option.

I use pv -e -o"%i %r %d %l"

With this pv command you can find which process is the axis process to 
have the id to be able to selectively kill it.

On UNIX (Solaris) you can achieve the same using /usr/ucb/ps -auxww . 
Not sure other UNIXes.

Regards,

Antoine

On 1/19/2011 4:17 AM, Jan C. wrote:
> Hello,
> I use ant to run some JUnit test. My JUnit test need a http server so
> I also start one in my test:
>
> <target name="mytest" depends="build">
> <parallel failonany="true">
>      <sequential>
>        <!-- Start HTTP server here -->
>         <java fork="yes"
> classname="org.apache.axis2.transport.http.SimpleHTTPServer">
>            ...
>      </sequential>
>      <sequential>
>        <!-- Run JUnit tests here-->
>         <junit>  ...
>      </sequential>
> </parallel>
> </target>
>
>
> The problem I have is that the SimpleHTTPServer is running forever so
> even when my JUnit test finish successfully, the ant target does not
> terminate. I can only terminate it using Ctrl+C. Since I want this
> target to be automated, I would like to find a way to "successfully"
> stop the ant target when the junit task finishes.
>
> Any ideas ?
>
> cheers,
> Jan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org