Here is a part of my build.xml:
<target name="run">
<java jar="${jar.dir}/${Main.class}.jar"
fork="yes"
<assertions>
<enable />
</assertions>
</java>
</target>
or
<target name="run">
<java classname="${Main.class}" classpath="${classes.dir};${lib.dir}" fork="yes"/>
</target>
Here is an example java code:
public class Test {
public Test() {
System.out.print("Test2");
}
public static void main(String[] args) {
System.out.println("Test1");
new Test();
while(true) {}
}
}
If I run this code from command line I have "Test1" and then "Test2". If I run this code using the Ant I have only "Test1".
How can I solve this problem?
You'll probably find that Ant buffers the output to System.out of your program by line before printing to stdout, and because your program never terminates (the while (true) {}), Ant is waiting for the program to finish before flushing the output of the line. Try changing the Test constructor to use println and you'll see the output.
This should solve the problem.
System.out.flush();
Add it before you get into an infinite loop. (EDIT:) and after you call new Test()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With