Results 1 to 1 of 1
- 07-24-2007, 09:34 PM #1
Member
- Join Date
- Jul 2007
- Posts
- 1
- Rep Power
- 0
Executing Ant code pragramatically
Hello,
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.setErrorPrintStream(System.err);
consoleLogger.setOutputPrintStream(System.out);
consoleLogger.setMessageOutputLevel(Project.MSG_IN FO);
project.addBuildListener(consoleLogger);
try {
project.fireBuildStarted();
project.init();
ProjectHelper helper = ProjectHelper.getProjectHelper();
project.addReference("ant.projectHelper", helper);
helper.parse(project, buildFile);
project.executeTarget(project.getDefaultTarget());
project.fireBuildFinished(null);
} catch (BuildException e) {
project.fireBuildFinished(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 org.apache.tools.ant package.Last edited by MikeO; 07-24-2007 at 09:44 PM.
Similar Threads
-
Executing stored procedures
By mew in forum JDBCReplies: 3Last Post: 08-20-2008, 05:47 PM -
Problem with executing
By mcal in forum New To JavaReplies: 2Last Post: 02-09-2008, 01:51 PM -
executing the java file
By TheBayWatchMan in forum New To JavaReplies: 4Last Post: 01-12-2008, 09:31 AM -
Executing Batch
By zcoarens in forum New To JavaReplies: 0Last Post: 08-14-2007, 09:49 AM -
Executing a jar file
By peiceonly in forum New To JavaReplies: 2Last Post: 04-06-2007, 02:32 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks