ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Marc Farrow" <>
Subject dev-list - Calling Ant within a servlet/webapp
Date Wed, 16 Aug 2006 12:26:13 GMT
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.setUserProperty("ant.file", buildfile.getPath());
     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(null);
//     project.setCoreLoader(this.getClass().getClassLoader());
//     project.setCoreLoader(Thread.currentThread
} catch (Exception e) {
     throw new RuntimeException(e);
} finally {
     project = null;
     buildfile = null;

Marc Farrow

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message