使用Java和Gradle的控制台应用程序 [英] Console application with Java and gradle
问题描述
我正在用Java和Gradle编写一个控制台应用程序。我正在使用 应用程序
插件并拥有必须在 build.gradle
中配置。
I am writing a console application with Java and gradle. I am using the application
plugin and have the required fields correctly configured in build.gradle
.
在我的主类中,我有 BufferedReader
链接到 System.in
。问题出在这里:当我在项目目录中运行 gradle run
时,阅读器不会等待我的控制台输入。 BufferedReader#readLine
会在第一次调用时返回 null
。这种行为不适合我在做什么。
In my main class I have BufferedReader
linked with System.in
. Here's the problem: When I run gradle run
in project directory, the reader does not wait for my console input. BufferedReader#readLine
instead returns null
on the very first call. This behavior is not desirable for what am I doing.
解决方案是什么?有没有一个单独的控制台应用程序插件gradle或我需要调整应用程序
插件以某种方式适合我的需要?
What is the solution? Is there a separate console application plugin for gradle or do I need to tweak application
plugin somehow to suit my needs?
推荐答案
默认情况下,您的gradle构建的system.in与运行(JavaExec)任务的system.in没有连接。您可以执行以下操作:
Per default the system.in of your gradle build is not wired up with the system.in of the run (JavaExec) task. You can do the following:
run{
standardInput = System.in
}
这篇关于使用Java和Gradle的控制台应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!