Simple Java App可与Ant一起使用,但不适用于Maven。我该怎么做才能纠正这个问题?

问题描述 投票:0回答:1

我正在使用带有Java 10.0.1 + 9的Netbeans 11.2,并创建了JavaApp。

package hellowant;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int number1;
        int number2;
        int sum;
        String str;
        Scanner input = new Scanner(System.in);

        System.out.print ("Enter first integer: ");
        str = input.nextLine ();
        number1 = Integer.parseInt(str);
        System.out.print ("Enter second integer:");
        str =input.nextLine ();
        number2 = Integer.parseInt(str);
        sum = number1 + number2;

        System.out.printf ( "Sum is %d\n", sum);
    }
}

当我使用Ant创建项目并在Netbeans调试器中运行它时,它运行良好。但是,我也尝试将项目作为Maven和Gradle项目运行,并且在这两种情况下,程序均无法获取`Input.nextline()。我已经找到调试消息:附加到localhost:5005连接被拒绝。我无法识别Maven或Gradle中的设置来解决此问题。

java maven gradle netbeans ant
1个回答
0
投票

通常,当您在任何端口上遇到连接被拒绝的异常情况时,意味着您已经在其他位置使用该端口(或者您完全没有权限绑定到该端口,在这里不太可能)。

您确定您没有正在运行的ant副本或maven或gradle副本吗?我将关闭IDE,并确保任务管理器/ etc报告没有Java应用程序,然后重试。

© www.soinside.com 2019 - 2024. All rights reserved.