使用Java和Gradle的控制台应用程序 [英] Console application with Java and gradle

查看:128
本文介绍了使用Java和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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆