ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tom Cunningham <>
Subject Re: dev-list - Calling Ant within a servlet/webapp
Date Wed, 16 Aug 2006 13:19:58 GMT

Have you taken a look at Anthill (
  There's an open source version which you can hack up, but it seems like it does the same
thing that you are trying to do here (kick off ant from the web).     If you do need to do
this, you might want to check the code in their open source version for how they handle their

On Wednesday, August 16, 2006, at 08:27AM, Marc Farrow <> wrote:

>I have some servlet and I am trying to call an Ant script within the class
>to compile a "project".  All of the references in the build script are not
>relative, therefore some of the classpath references are not correct.  I
>know I can change the properties, etc to fix this.  However, due to the
>nature of our environment we do not want to do this.  With all that being
>said, I do know that all the classpath entries that I need to compile the
>needed classes are within my current servlet container (in my case Tomcat).
>What can I do retrieve the correct classloader so that all the classes are
>visible to the Ant script.  Below is a snippet of code I am using.  In
>comments, you will see the various ways I have tried to call the
>setCoreLoader method.
>Thank you,
>File buildfile = null;
>try {
>     buildfile = new File(this.workingDirectory.getPath() + "/build.xml");
>     Project project = new Project();
>     project.setBaseDir(this.workingDirectory);
>     project.setName(this.project);
>     project.setUserProperty("ant.file", buildfile.getPath());
>     project.init();
>     ProjectHelper helper = ProjectHelper.getProjectHelper();
>     project.addReference("ant.projectHelper", helper);
>     helper.parse(project, buildfile);
>     Properties sysProps = System.getProperties();
>     for (Iterator it = sysProps.entrySet().iterator();it.hasNext();) {
>  Map.Entry entry = (Map.Entry);
>  project.setProperty(entry.getKey().toString(), entry.getValue
>     }
>     project.setProperty("basedir", project.getBaseDir().getPath());
>     project.setProperty("", project.getName());
>     project.setProperty("ant.file", buildfile.getPath());
>     project.setCoreLoader(Thread.currentThread().getContextClassLoader());
>//     project.setCoreLoader(null);
>//     project.setCoreLoader(this.getClass().getClassLoader());
>//     project.setCoreLoader(Thread.currentThread
>     project.execute("dist");
>} catch (Exception e) {
>     throw new RuntimeException(e);
>} finally {
>     project = null;
>     buildfile = null;
>Marc Farrow

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message