You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Mahfudh Junaryanto <ma...@readiminds.com> on 2002/12/20 05:09:19 UTC

Application CLOSE after running org.apache.tools.ant.Main.main()


Hi ,

My Java Application (Swing) closed after executing
org.apache.tools.ant.Main.main(). Anybody have a clue to what have
happened?
I even created separate thread when running
org.apache.tools.ant.Main.main(). It did not help.

Thanks in advance !

-mj-

Re: Application CLOSE after running org.apache.tools.ant.Main.main()

Posted by Steve Loughran <st...@iseran.com>.
----- Original Message -----
From: "Erik Hatcher" <ja...@ehatchersolutions.com>
To: "Ant Users List" <an...@jakarta.apache.org>
Sent: Friday, December 20, 2002 06:31
Subject: Re: Application CLOSE after running
org.apache.tools.ant.Main.main()


> Joey Gibson wrote:
> > On Fri, 20 Dec 2002 08:38:45 -0500, Erik Hatcher
> > <ja...@ehatchersolutions.com> wrote:
> >
> > ||| Ant's Main.main calls System.exit, that is why.
> >
> > I got bitten by a System.exit() call a while back (not Ant's main, but
> > another). I was wrapping a local utility in an Ant task and while the
task
> > ran and the tool did its job, Ant would just abort with no errors, no
> > messages, nothing. After a little fiddling I discovered it was a call to
> > exit(). Is the reason for Ant's main calling System.exit() simply to
return
> > an exit code to the OS? That's what it looks like. A cursory glance at
> > Ant's Main.start() method looks like one could use the
> > additionalUserProperties element to pass a property like "exit=true" or
> > something like that and then Ant could check that before calling
> > System.exit().
>
> Yes, I'm pretty sure thats the primary (only?) reason for the call to
> System.exit.
>
> But it seems folks should be integrating with Ant by emulating what
> Main.main does rather than simply invoking it directly.  I've toyed with
> writing a servlet that ran Ant once upon a time.  I just dug up the code
> and here it is:
>
>      final Project project = new Project();
>      AntListener listener = new AntListener();
>      project.addBuildListener(listener);
>      File buildFile = new File(buildFile);
>
>      Throwable exception = null;
>      try {
>        project.fireBuildStarted();
>        project.init();
>        ProjectHelper.configureProject(project, buildFile);
>        project.executeTarget(project.getDefaultTarget());
>      }
>      catch (BuildException e) {
>        exception = e;
>      }
>      finally {
>        project.fireBuildFinished(exception);
>
>        Writer out = response.getWriter();
>        out.write(listener.getLog());
>      }
>

This should be a taglib, surely, one that takes stuff inline...


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Application CLOSE after running org.apache.tools.ant.Main.main()

Posted by Erik Hatcher <ja...@ehatchersolutions.com>.
Joey Gibson wrote:
> On Fri, 20 Dec 2002 08:38:45 -0500, Erik Hatcher
> <ja...@ehatchersolutions.com> wrote:
> 
> ||| Ant's Main.main calls System.exit, that is why.
> 
> I got bitten by a System.exit() call a while back (not Ant's main, but
> another). I was wrapping a local utility in an Ant task and while the task
> ran and the tool did its job, Ant would just abort with no errors, no
> messages, nothing. After a little fiddling I discovered it was a call to
> exit(). Is the reason for Ant's main calling System.exit() simply to return
> an exit code to the OS? That's what it looks like. A cursory glance at
> Ant's Main.start() method looks like one could use the
> additionalUserProperties element to pass a property like "exit=true" or
> something like that and then Ant could check that before calling
> System.exit(). 

Yes, I'm pretty sure thats the primary (only?) reason for the call to 
System.exit.

But it seems folks should be integrating with Ant by emulating what 
Main.main does rather than simply invoking it directly.  I've toyed with 
writing a servlet that ran Ant once upon a time.  I just dug up the code 
and here it is:

     final Project project = new Project();
     AntListener listener = new AntListener();
     project.addBuildListener(listener);
     File buildFile = new File(buildFile);

     Throwable exception = null;
     try {
       project.fireBuildStarted();
       project.init();
       ProjectHelper.configureProject(project, buildFile);
       project.executeTarget(project.getDefaultTarget());
     }
     catch (BuildException e) {
       exception = e;
     }
     finally {
       project.fireBuildFinished(exception);

       Writer out = response.getWriter();
       out.write(listener.getLog());
     }

AntListener is just a BuildListener implementing class that collects all 
the log messages for grabbing later (in the finally clause).  This is 
just a simple example, and one that probably needs lots of improvement 
to be solid, but its better than calling Main.main, IMO.

	Erik


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Application CLOSE after running org.apache.tools.ant.Main.main()

Posted by Joey Gibson <jo...@joeygibson.com>.
On Fri, 20 Dec 2002 08:38:45 -0500, Erik Hatcher
<ja...@ehatchersolutions.com> wrote:

||| Ant's Main.main calls System.exit, that is why.

I got bitten by a System.exit() call a while back (not Ant's main, but
another). I was wrapping a local utility in an Ant task and while the task
ran and the tool did its job, Ant would just abort with no errors, no
messages, nothing. After a little fiddling I discovered it was a call to
exit(). Is the reason for Ant's main calling System.exit() simply to return
an exit code to the OS? That's what it looks like. A cursory glance at
Ant's Main.start() method looks like one could use the
additionalUserProperties element to pass a property like "exit=true" or
something like that and then Ant could check that before calling
System.exit(). 

Joey



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Application CLOSE after running org.apache.tools.ant.Main.main()

Posted by Erik Hatcher <ja...@ehatchersolutions.com>.
Ant's Main.main calls System.exit, that is why.

Mahfudh Junaryanto wrote:
> 
> Hi ,
> 
> My Java Application (Swing) closed after executing
> org.apache.tools.ant.Main.main(). Anybody have a clue to what have
> happened?
> I even created separate thread when running
> org.apache.tools.ant.Main.main(). It did not help.
> 
> Thanks in advance !
> 
> -mj-
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>