You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bu...@apache.org on 2009/09/16 23:46:03 UTC

DO NOT REPLY [Bug 47854] New: Ant can't run within another Java program

https://issues.apache.org/bugzilla/show_bug.cgi?id=47854

           Summary: Ant can't run within another Java program
           Product: Ant
           Version: 1.7.1
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Core
        AssignedTo: notifications@ant.apache.org
        ReportedBy: bugzilla@byrden.com


My current shell is XMLSH, a Java program that loads Ant into its own VM. But I
had to modify 2 classes to make this work. Ant 1.7.1 is an ill-behaved guest in
the VM Because:

[1] It calls System.exit() which kills the entire VM. 
[2] It makes an unwarranted assumption about its ClassLoaders

Re [1] : there are calls to System.exit() in both the Launcher class and the
Main class. I can extend Main to change this, but not Launcher.

In my opinion (I have Java programmer certification) no Java program should
need to kill the VM unless something is wrong. 

Re [2] : on loading Ant, I see this:
"org.apache.tools.ant.Main cannot be cast to
org.apache.tools.ant.launch.AntMain"

Reason: the Launcher class makes 2 ClassLoaders and assumes they will connect
up in a parent-child relationship. For me, they don't. I can see no reason why
Launcher should not make that connection explicitly.

Note: after changing these 2 classes, I am able to run Ant under XMLSH with a
very simple wrapper script.

David

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

DO NOT REPLY [Bug 47854] Ant can't run within another Java program

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=47854

--- Comment #1 from Martin Gainty <mg...@hotmail.com> 2009-09-25 11:12:42 PDT ---
i just saw this post noting 
"the Launcher class makes 2 ClassLoaders and assumes they will connect
up in a parent-child relationship. For me, they don't. I can see no reason why
Launcher should not make that connection explicitly."

i came upon this issue when another Java apache project produced classloader
error
"org.apache.tools.ant.Main cannot be cast to
org.apache.tools.ant.launch.AntMain"

(attempting to pass its own CL to Ant and failed)

can we vote to accept davids mods as a workaround to this issue?

thanks
Martin

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

DO NOT REPLY [Bug 47854] Ant can't run within another Java program

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=47854

--- Comment #2 from J.M. (Martijn) Kruithof <jk...@apache.org> 2009-10-01 13:56:50 PDT ---
Launcher only calls System.exit() in case something went wrong (non-zero exit
status) Main also calls System.exit for a 0 exit status in case nothing went
wrong (This may not be necessary, will investigate). Launcher is strictly meant
to be used from the command line. Does it make sense to modify Launcher to
solve [2] without fully solving [1], please note the System.exit calls are
needed in Launcher and Main to indicate to the shell that something went wrong.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

DO NOT REPLY [Bug 47854] Ant can't run within another Java program

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=47854

--- Comment #3 from Stefan Bodewig <bo...@apache.org> 2009-10-09 01:12:23 PDT ---
Like Martijn said, Ant's Main has a very good reason to call System.exit,
namely to have control over the process' exit code which is vital to many
shell-script/batch-file scenarios.

The System.exit in Launcher will only ever be triggered if the AntMain
implementation throws an exception.  Since you need to plug in your own AntMain
implementation anyway, this should be easy to avoid.

For [2]: what does you modified implementation look like and would you be
willing to contribute it?

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

[Bug 47854] Ant can't run within another Java program

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=47854

Stefan Bodewig <bo...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |NEEDINFO

-- 
You are receiving this mail because:
You are the assignee for the bug.