I just started using Ant 1.8.2 as it was installed along with the latest Java
Update for the Mac (JavaForMacOSX10.6Update4). Projects that worked fine with
Ant 1.8.1 no longer work in 1.8.2. The problem seems to be that a Java task
that forks a jvm hangs when it tries to read from System.in. Has anyone else
seen this problem?
Below is a simple build.xml file that demonstrates the problem. It creates a
simple Java file that just calls readLine() and echos the input, compiles the
file, and runs it twice: once in a non-forked JVM, which works fine, and again
in a forked JVM, which hangs.
-- Ron --
Here is a sample output:
> ant
Buildfile: /Users/Ron/Development/Spots/tmp/ant-test/build.xml
compile:
[echo]
[echo] ant.version = Apache Ant(TM) version 1.8.2 compiled on December
20 2010
[echo] ant.home = /usr/share/ant
[echo] ant.library.dir = /usr/share/ant/lib
[echo] ant.java.version = 1.6
[echo]
[javac] Compiling 1 source file to /Users/Ron/Development/Spots/tmp/ant-test
good:
[echo] This will work: calling Java with fork=false
[java]
[java] Please enter some text and hit return:
asdf
[java] Text entered = asdf
bad:
[echo] This will hang: calling Java with fork=true
[java]
[java] Please enter some text and hit return:
asdf
ddfd
C-c C-c
>
And here's the build.xml file:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="test-all" name="java-input-bug">
<!--
Build file to demonstrate a bug with ant version 1.8.2 running in Mac
OS X 10.6
using the latest JavaForMacOSX10.6Update4, Java version 1.6.0_24.
Do "ant bad" to run a Java app that just reads in a line of text &
echos it.
If run in a forked JVM the program hangs waiting for input.
Doing "ant good" to run it in a non-forked JVM works fine, as does
directly
executing it with the command "java Test".
Everything works fine with ant version 1.8.1.
-->
<target name="compile">
<echo>
ant.version = ${ant.version}
ant.home = ${ant.home}
ant.library.dir = ${ant.library.dir}
ant.java.version = ${ant.java.version}
</echo>
<echo file="Test.java">
import java.io.*;
public class Test {
public static void main(String[] args) throws IOException {
System.out.println("\nPlease enter some text and hit return:");
String line = new BufferedReader(new
InputStreamReader(System.in)).readLine();
System.out.println("Text entered = " + line);
}
}
</echo>
<javac srcdir="."
destdir="."
includeAntRuntime="no"
includeJavaRuntime="no"
debug="false"
fork="yes"/>
</target>
<target name="bad" depends="compile">
<echo message="This will hang: calling Java with fork=true"/>
<java classname="Test"
classpath="."
fork="true"
failonerror="true"/>
</target>
<target name="good" depends="compile">
<echo message="This will work: calling Java with fork=false"/>
<java classname="Test"
classpath="."
fork="false"
failonerror="true"/>
</target>
<target name="test-all" depends="good, bad"/>
</project>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]