Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

antcall causes FileNotFoundException if using executeTarget within java

807606Mar 12 2007 — edited Mar 12 2007
Hi all,

this is my first post here, so i dont know if it's the right place (sorry if so).

I try to run an ant target within a java program.
My build file (test.xml) is:
<project name="test" default="usage" basedir=".">
  <target name="test1" >
    <echo message="Target test1" />
    <antcall target="test2"/>
  </target>
  <target name="test2" >
    <echo message="Target test2" />
  </target>
</project>
My java programm is:
public static void main (String [] a) {
  String buildFileName = "test.xml";
  File buildFile = new File (".",buildFileName);
  Project project = new Project();
  project.init();
  ProjectHelper helper = new ProjectHelperImpl();
  helper.parse(project, buildFile);
  project.executeTarget("test1");	
}
This causes following exception:

Exception in thread "main" test.xml:4: The following error occurred while executing this line:
java.io.FileNotFoundException: build.xml 
	at org.apache.tools.ant.ProjectHelper.addLocationToBuildException(ProjectHelper.java:539)
	at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:336)
	at org.apache.tools.ant.taskdefs.CallTarget.execute(CallTarget.java:107)
	at org.apache.tools.ant.Task.perform(Task.java:364)
	at org.apache.tools.ant.Target.execute(Target.java:341)
	at org.apache.tools.ant.Target.performTasks(Target.java:369)
	at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
	at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
	at test.Test.main(Test.java:19)
Caused by: java.io.FileNotFoundException: build.xml 
	at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:243)
	at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:140)
	at org.apache.tools.ant.ProjectHelper.configureProject(ProjectHelper.java:91)
	at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:334)
	... 7 more
Caused by: java.io.FileNotFoundException: build.xml 
	at java.io.FileInputStream.open(Native Method)
	at java.io.FileInputStream.<init>(FileInputStream.java:106)
	at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:198)
	... 10 more
If I use
<ant antfile="test.xml" target="test2"/>
instead it works perfecly. But I don't want to. The target "antcall" was created to call targets within the same build-file, but why build.xml is referenced anywhere?

Might this be an ant bug?
Any ideas?

Tx
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 9 2007
Added on Mar 12 2007
1 comment
651 views