Return-Path: Delivered-To: apmail-jakarta-ant-user-archive@apache.org Received: (qmail 2550 invoked from network); 29 May 2002 03:02:41 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 29 May 2002 03:02:41 -0000 Received: (qmail 26710 invoked by uid 97); 29 May 2002 03:02:34 -0000 Delivered-To: qmlist-jakarta-archive-ant-user@jakarta.apache.org Received: (qmail 26694 invoked by uid 97); 29 May 2002 03:02:34 -0000 Mailing-List: contact ant-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Users List" Reply-To: "Ant Users List" Delivered-To: mailing list ant-user@jakarta.apache.org Received: (qmail 26675 invoked by uid 98); 29 May 2002 03:02:33 -0000 X-Antivirus: nagoya (v4198 created Apr 24 2002) Message-ID: <040101c206bd$44a736b0$6401a8c0@darden.virginia.edu> From: "Erik Hatcher" To: "Ant Users List" References: Subject: Re: Hi, all. How do I protect myself from System.exit? Date: Tue, 28 May 2002 23:02:28 -0400 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N A good way to do it is to re-use the task internally, and set the fork mode on it. Here's an example that is actually a straight cut-and-paste from our "Writing Ant tasks" chapter: public void execute() throws BuildException { Java javaTask = null; javaTask = (Java) project.createTask("java"); javaTask.setTaskName("search"); javaTask.setClassname("org.example.antbook.tasks.Searcher"); javaTask.setClasspath(classpath); javaTask.createArg().setFile(indexDir); javaTask.createArg().setValue(query); javaTask.setFork(true); if (javaTask.executeJava() != 0) { throw new BuildException("error"); } } I have setters on my task that take the indexDir (java.io.File) and query (String), as well as allowing nested classpath and classpath/classpathref attributes. Erik ----- Original Message ----- From: "Scott Ellsworth" To: "Ant List" Sent: Tuesday, May 28, 2002 10:57 PM Subject: Hi, all. How do I protect myself from System.exit? > Hi, all. > > I have a task that I have written that calls the main method of a java > class after doing some parameter munging. This main method does a > System.exit. I cannot easily rewrite that part of the code, so I need > to work around it. > > I presume the "right way" is to just fork. I looked at the docs, and it > indicates that Java and ExecuteJava will handle this, but I kind of > foundered looking at the taskdef javadocs for Java and ExecuteJava. > > Assuming I have a Task already written with a stack of instance > variables, getters, setters, and a working execute method that ends with > a call to the main class of the thing I am wrapping. > > Can anyone point me to how I need to modify this to use the appropriate > fork code? What follows is my best attempt, but the call appears to not > have the same classpath as the task that spawned it. > > public class AntIntercalateTask extends Task { > boolean _theParam=false > public void setTheParam(boolean theParam) > { > _theParam=setTheParam; > } > public AntIntercalateTask() > { > } > execute() > { > // worked, save for System.exit > //String[] args={"param1", "value1"}; > //com.Foo.main(args); > > // cannot find classpath > > CommandlineJava cmdline = new CommandlineJava(); > cmdline.createArgument().setValue("param1"); > cmdline.createArgument().setValue("value1"); > prepareArguments(cmdline); > cmdline.setClassname("com.Foo"); > > Execute exe=new Execute(); > exe.setCommandline(cmdline.getCommandline()); > try{ > exe.execute(); > } catch (Exception e){ > System.out.println(e); > } > } > } > > So, how can I transplant the classpath from the taskdef? > > Scott > > > -- > To unsubscribe, e-mail: > For additional commands, e-mail: > > -- To unsubscribe, e-mail: For additional commands, e-mail: