2

I have added few system.in inputs (user inputs) in an interactive way. I have created executable jar and I am using apache ant to compile and run the program. When I execute it with java -jar jarfile.jar, the program interacts fine and take the user input through buffered reader system.in, but when I run it through apache ant by ant run, it hangs after taking first input.

Why with apache ant, it is not taking System.in inputs typed through keyboard?

Do I have to add something in the run target java task of apache ant?

Colin 't Hart
  • 7,372
  • 3
  • 28
  • 51
Natha Kamat
  • 71
  • 1
  • 5
  • 16
  • 1
    Can you please add some snippet of code, that you are using to call the Java from Ant? – Niraj Chapla Oct 14 '13 at 02:57
  • 1
    possible duplicate of [Ant exec task: How can I read input from console stdin?](http://stackoverflow.com/questions/4176305/ant-exec-task-how-can-i-read-input-from-console-stdin) – Stephen C Oct 14 '13 at 08:03
  • 1
    The short answer is that reading console input from an Ant task is not supported. – Stephen C Oct 14 '13 at 08:04

1 Answers1

1

Reading console input from the task is not allowed.

But you can do take console inputs from the user with ant and pass it to the command line argument to the Java program.

Following is the sample ant script which is taking input from the user and passing it to the java program. And Java program is printing it.

Ant Script:

<project name="Testing" basedir="../bin" default="run">
  <target name ="run">
    <property name="name" value="Test"/>
    <input message="Enter your Name :" addproperty="inputvalue"  defaultvalue="n" />
    <echo message="${inputvalue}"/>
        <java classname="${name}" failonerror="true" dir="${basedir}" spawn="false" fork="false"  >
        <classpath>
            <pathelement location="${basedir}" />
        </classpath>
        <arg value="${inputvalue}"/>
    </java>
  </target>
</project>

Java Program:

public class Test {

public static void main(String[] args) throws IOException {

        System.out.println("Hello " + args[0]);  
}
}
Niraj Chapla
  • 2,149
  • 1
  • 21
  • 34