Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-24-2007, 11:34 PM
Member
 
Join Date: Jul 2007
Posts: 1
MikeO is on a distinguished road
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 11:44 PM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Executing stored procedures mew Database 3 08-20-2008 07:47 PM
Problem with executing mcal New To Java 2 02-09-2008 03:51 PM
executing the java file TheBayWatchMan New To Java 4 01-12-2008 11:31 AM
Executing Batch zcoarens New To Java 0 08-14-2007 11:49 AM
Executing a jar file peiceonly New To Java 2 04-06-2007 04:32 PM


All times are GMT +3. The time now is 09:28 AM.


VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org