Return-Path: Delivered-To: apmail-tomcat-users-archive@www.apache.org Received: (qmail 65333 invoked from network); 9 Apr 2006 07:41:24 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 9 Apr 2006 07:41:24 -0000 Received: (qmail 19836 invoked by uid 500); 9 Apr 2006 07:41:12 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 19812 invoked by uid 500); 9 Apr 2006 07:41:12 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 19801 invoked by uid 99); 9 Apr 2006 07:41:12 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 09 Apr 2006 00:41:12 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [217.175.253.222] (HELO brain.myhosting.de) (217.175.253.222) by apache.org (qpsmtpd/0.29) with SMTP; Sun, 09 Apr 2006 00:41:11 -0700 Received: (qmail 54321 invoked by uid 90); 9 Apr 2006 07:40:48 -0000 Received: from unknown (HELO ?192.168.1.10?) (rolf@august.de@82.139.199.175) by 0 with ESMTPA; 9 Apr 2006 07:40:48 -0000 Message-ID: <4438BA7E.8010102@august.de> Date: Sun, 09 Apr 2006 09:40:46 +0200 From: Rolf Schumacher User-Agent: Mail/News 1.5 (X11/20060228) MIME-Version: 1.0 To: Tomcat Users List Subject: Re: calling ant launcher References: <4438063A.3010902@august.de> In-Reply-To: <4438063A.3010902@august.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Found a good explenation for my error here: http://www.jspwiki.org/wiki/A2AClassCastException Building a servlet that invokes Ant, one should not use the Launcher.java in favor of the Ant class Project.java: This is my invoker - assuming ant.jar, ant-launcher.jar and e.g. ant-trax.jar in WEB-INF/lib: private void execAnt( Properties properties, String buildFile ) { try { // create a project final Project project = new Project(); // Add the default listener - a simple Logger extending BuildLogger project.addBuildListener( new AntLogger() ); // set the classloader project.setCoreLoader(this.getClass().getClassLoader()); // set the input handler, don't know if this is really needed project.setInputHandler(new DefaultInputHandler()); // init project.init(); // set the version and other properties project.setUserProperty(MagicNames.ANT_VERSION, "unknown" ); for( Object property: properties.keySet() ) project.setUserProperty( (String)property, properties.getProperty( (String)property) ); // set the path to the build file project.setUserProperty(MagicNames.ANT_FILE, buildFile ); // configure the project ProjectHelper.configureProject(project, new File( buildFile) ); // set the target Vector targets = new Vector(); targets.addElement(project.getDefaultTarget()); // execute the project project.executeTargets(targets); } catch( Throwable t ) { log.error( FAILED, t ); } finally {} } Rolf Schumacher wrote: > Dear Tomcat professionals, > > I tried to automate some installation over the Web > I got a class cast exception when trying to launch Ant from a servlet. > The program works fine if I execute it from the command line. > In a servlet under Tomcat it causes a > > java.lang.ClassCastException: org.apache.tools.ant.Main > at org.apache.tools.ant.launch.Launcher.run(Launcher.java:275) > at org.apache.tools.ant.launch.Launcher.main(Launcher.java:96) > > I looked up line 275 in Launcher.java: > > 270 URLClassLoader loader = new URLClassLoader(jars); > 271 Thread.currentThread().setContextClassLoader(loader); > 272 Class mainClass = null; > 273 try { > 274 mainClass = loader.loadClass(MAIN_CLASS); > 275 AntMain main = (AntMain) mainClass.newInstance(); > 276 main.startAnt(newArgs, null, null); > > Do you have an idea why the loader does load something different > that usually can be casted to AntMain? > > Any help appreaciated. > > Rolf > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org > For additional commands, e-mail: users-help@tomcat.apache.org > > > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org For additional commands, e-mail: users-help@tomcat.apache.org