简体   繁体   中英

Java program expecting input doesn't work when running from Ant?

So I have a simple java program that prints a message and asks for user input. The program runs fine, until I try to run it through ant.

When I use the below build file, the program never prints the message.

When I run with ant -verbose, it says that "The ' characters around the executable and the arguments are not part of the command"

What am I doing wrong in the build file? I'm confused because this build file works fine for programs that don't ask for user input.

<project name="lab4" default="run" basedir=".">

    <property name="src" value="."/> 

    <target name="clean">
       <delete>
              <fileset dir="${src}" includes="**/*.class,META-INF,*/**.jar"/>
           </delete>
    </target>

    <target name="compile" depends="clean">
        <javac srcdir="${src}" destdir="${src}" includes="**/*.java"  includeantruntime="false"/>
    </target>

    <target name="run" depends="compile">
      <java classpath="${src}" classname="CountLetters1" failonerror="yes"/>
    </target>

</project>

Summarizing the "solution" from the comments to the question:

The problem here appears to be that the program does not include a line break in its input prompt. This causes Ant to not show the prompt (it's waiting for the newline).

Other than that, the example is actually running fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM