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?
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]);
}
}
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