tags:

views:

531

answers:

1

I have a .java file and am compiling it using javac in ant. The .class file goes to output directory. A.class when ran, produces a.txt.

How to run the ant ´java´ task and where will the a.txt go, when ran? I mean which directory? Can I specify the direc. where the output files of java task should go?

+4  A: 

Take a look at this for reference:

http://ant.apache.org/manual/CoreTasks/java.html

It contains an example of using the Java task to run a specific class, e.g:

<target name="run">
     <java classname="A">
             <classpath>
               <pathelement location="output"/>
               <pathelement path="${java.class.path}"/>
             </classpath>
     </java>
</target>

It really depends on where you are writing the file out to from A.java. If it is in the current directory, e.g:

File f = new File("./test.txt");
f.createNewFile();

then it will output the file relative to where you ran the build file from.

Hope that helps.

Jon
Also look into the "dir" attribute on the <java> ant task. If you set fork="true", ant starts a new JVM for the program you're running. You can control its working directory by setting dir="${basedir}/whatever".
jpdaigle