Results 1 to 1 of 1
  1. #1
    MikeO is offline Member
    Join Date
    Jul 2007
    Rep Power

    Default Executing Ant code pragramatically


    I am trying to execute an ant script programmatic ally via Java code. I know the build file works, because when I run it in Eclipse, it does exactly what I want it to. However, when I try to run the Java class that executes the build script, I have a problem. The script starts to run, but fails on the <junit> task because it can't find it. Within Eclipse, it works since I have the classpath parameters set up, so it knows where to look for the jar file.

    What I need to know how to do is either:
    a) how to modify the library that ant uses with Java code (ie: basically doing "ant -lib junit.jar" in java code OR
    b) if there is an easier way to do this altogether (such as using AntRunner, or executing command line commands within java code)

    I have done several google searches, and the way I have started now is the only way that I have found so far. Here is the code snippet that launches the and build file:

    Project project = new Project();
    project.setUserProperty("ant.file", buildFile.getAbsolutePath());
    DefaultLogger consoleLogger = new DefaultLogger();
    consoleLogger.setMessageOutputLevel(Project.MSG_IN FO);

    try {
    ProjectHelper helper = ProjectHelper.getProjectHelper();
    project.addReference("ant.projectHelper", helper);
    helper.parse(project, buildFile);
    } catch (BuildException e) {

    Thank you in advance for any help. It is greatly appreciated.

    Edit: I should also mention that the classes being used are in the package.
    Last edited by MikeO; 07-24-2007 at 09:44 PM.

Similar Threads

  1. Executing a jar file
    By peiceonly in forum New To Java
    Replies: 7
    Last Post: 02-14-2014, 09:02 AM
  2. Executing stored procedures
    By mew in forum JDBC
    Replies: 3
    Last Post: 08-20-2008, 05:47 PM
  3. Problem with executing
    By mcal in forum New To Java
    Replies: 2
    Last Post: 02-09-2008, 01:51 PM
  4. executing the java file
    By TheBayWatchMan in forum New To Java
    Replies: 4
    Last Post: 01-12-2008, 09:31 AM
  5. Executing Batch
    By zcoarens in forum New To Java
    Replies: 0
    Last Post: 08-14-2007, 09:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts