3

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?

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Yeap, I see that. But how can repair it? It's only an example, but I need to use exactly "System.out.print".
1

This should solve the problem.

System.out.flush(); 

Add it before you get into an infinite loop. (EDIT:) and after you call new Test()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.