You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@buildr.apache.org by Ander Juaristi <aj...@gmx.es> on 2015/04/08 09:44:27 UTC

Buildr terminates after RJB invocation

Hi,

I've got a legacy ant script called deploy.xml, and I'm running it through a Buildr buildfile, like this:

     Java.org.apache.tools.ant.Main.main(['-buildfile', 'deploy.xml'])

So far it runs OK, but there are a bunch of Ruby lines after it that don't get executed. The whole Buildr process seems to terminate after the Ant invocation completes.

I've tried using a separate thread, but nothing changes:
     t = Thread.new {
         Java.org.apache.tools.ant.Main.main(['-buildfile', 'deploy.xml'])
     }
     t.join

Finally, I've gone through AntWrap (http://antwrap.rubyforge.org), but looking at the documentation, it does not seem to be able to run legacy Ant scripts. At least, in a straightforward way.

Thoughts?

-- 
Regards,
- AJ

Re: Buildr terminates after RJB invocation

Posted by Ander Juaristi <aj...@gmx.es>.
On 04/08/2015 11:44 AM, Pepijn Van Eeckhoudt wrote:
> Simplest fix is to run Ant as a subprocess instead of in-process I think.

Fixed with Kernel.fork():

     fork {
         Java.org.apache.tools.ant.Main.main(['-buildfile', 'deploy.xml'])
     }
     Process.wait

Thanks!
-- 
Regards,
- AJ

Re: Buildr terminates after RJB invocation

Posted by Pepijn Van Eeckhoudt <pe...@vaneeckhoudt.net>.
Ant’s Main class calls System.exit and RJB starts the JavaVM within the Ruby process, not as a subprocess, so Ant ends up terminating the entire process. Simplest fix is to run Ant as a subprocess instead of in-process I think.
Alternative solution from an SO answer (http://stackoverflow.com/questions/8714262/invoke-ant-from-java-then-return-to-java-after-ant-termination <http://stackoverflow.com/questions/8714262/invoke-ant-from-java-then-return-to-java-after-ant-termination>) is to subclass Ant’s Main and override its exit method to be a noop.

Best regards,

Pepijn

> On 08 Apr 2015, at 09:44, Ander Juaristi <aj...@gmx.es> wrote:
> 
> Hi,
> 
> I've got a legacy ant script called deploy.xml, and I'm running it through a Buildr buildfile, like this:
> 
>    Java.org.apache.tools.ant.Main.main(['-buildfile', 'deploy.xml'])
> 
> So far it runs OK, but there are a bunch of Ruby lines after it that don't get executed. The whole Buildr process seems to terminate after the Ant invocation completes.
> 
> I've tried using a separate thread, but nothing changes:
>    t = Thread.new {
>        Java.org.apache.tools.ant.Main.main(['-buildfile', 'deploy.xml'])
>    }
>    t.join
> 
> Finally, I've gone through AntWrap (http://antwrap.rubyforge.org), but looking at the documentation, it does not seem to be able to run legacy Ant scripts. At least, in a straightforward way.
> 
> Thoughts?
> 
> -- 
> Regards,
> - AJ