ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Marc Farrow" <>
Subject Help with using Ant Project API through Java.
Date Thu, 16 Aug 2007 13:11:31 GMT
I have a build script (which just happens to be maintained by NetBeans) that
I am trying to execute targets on in java programmatically.  One of the
targets is called "dist" which will build a web project and create the
distributable jar.  I have code that programmatically retrieves all
dependent projects and jar files.  I have this listing of jars and I want to
add them to the "classpath" for the build.  However, I am unable to do so.
Can somone review the code below to make sure I am at least properly adding
the jars to ant's classpath.  The fact that the target may not be using the
classpath is ok.  I will try to resolve that separately as it would not be a
concern for ant user group.

        String buildfile = null;
        Project project;
        Path path;
        FileList filelist;
        ProjectHelper helper;
        try {
            buildfile = "build.xml";
            project = new Project();
            project.setUserProperty("ant.file", buildfile);
            helper = ProjectHelper.getProjectHelper();
            path = new Path(project);
            for (String pn : path.list()) {
                System.out.println("path-->" + pn);
            helper.parse(project, new File(this.workingDirectory.getPath() +
"/" + buildfile));
            Properties sysProps = System.getProperties();
            for (Iterator it = sysProps.entrySet().iterator();it.hasNext();)
                Map.Entry entry = (Map.Entry);
// can above code be replaced with project.setSystemProporties();
        } catch (Exception e) {
            if (debug) {
            if (e instanceof BuildException && e.getMessage().indexOf("") > -1) {
                System.err.println("WARNING!!! Unable to build project
because build.xml was not found for " + this.projectName);
            } else {
                throw new RuntimeException(e);
        } finally {
            path = null;
            filelist = null;
            project = null;
            buildfile = null;
            helper = null;
    private void addPathsFromClasspath(Path path) {
        List<FileSet> classpath = parseClasspath();
        for (FileSet fs : classpath) {

    private List<FileSet> parseClasspath() {
        List<FileSet> arList = new ArrayList<FileSet>();
        Set<String> set = new HashSet<String>();
        for (File file : getClasspath()) {
        for (String parent : set) {
            FileSet fs = new FileSet();
            fs.setDir(new File(parent));
        return arList;

    private List<File> getClasspath() {
      ....  // code to retrieve List of file references to classpath entries

Marc Farrow

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