Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么我的程序在使用maven打包后跳出循环?_Java_Maven_Deployment_Tcp_Package - Fatal编程技术网

Java 为什么我的程序在使用maven打包后跳出循环?

Java 为什么我的程序在使用maven打包后跳出循环?,java,maven,deployment,tcp,package,Java,Maven,Deployment,Tcp,Package,我已经编写了一个程序,使用TCP/IP在我的服务器之间发送当前IP。当我在IDE中运行程序时,一切正常,我得到了预期的结果,但当我使用Maven打包它时,程序只运行一次,并立即跳出循环。有人能帮我理解为什么会这样吗 public String getIP () throws UnknownHostException { InetAddress myIP=InetAddress.getLocalHost(); //System.out.println("My IP Ad

我已经编写了一个程序,使用TCP/IP在我的服务器之间发送当前IP。当我在IDE中运行程序时,一切正常,我得到了预期的结果,但当我使用Maven打包它时,程序只运行一次,并立即跳出循环。有人能帮我理解为什么会这样吗

public String getIP () throws UnknownHostException {
    InetAddress myIP=InetAddress.getLocalHost();

    //System.out.println("My IP Address is:");
    //System.out.println(myIP.getHostAddress());
    String IP = myIP.getHostAddress();

    return IP;
}

public String getID(){

    JFrame f;

    f=new JFrame();
    String ID=JOptionPane.showInputDialog(f,"Enter GSID");

    return ID;
}

public static void main(String args[]) throws IOException, InterruptedException {

    Socket s1 = null;
    BufferedReader br = null;
    BufferedReader is = null;
    PrintWriter pwr = null;

    client obj = new client();
    String CID = obj.getID();
    String response = null;

    while(true) {

        String ServerIP = "173.16.1.5";
            s1 = new Socket(ServerIP, 4445);
            br = new BufferedReader(new InputStreamReader(System.in));
            is = new BufferedReader(new InputStreamReader(s1.getInputStream()));
            pwr = new PrintWriter(s1.getOutputStream());

            // send ID to Server
            pwr.println(CID);
            pwr.flush();
            response = is.readLine();
            System.out.println("Server Response : " + response);

            // get IP and send to Server
            client IP = new client();
            String CIP = IP.getIP();

            pwr.println(CIP);
            pwr.flush();
            response = is.readLine();
            System.out.println("Server Response : " + response);

            // send time
            DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
            LocalDateTime now = LocalDateTime.now();
            pwr.println(dtf.format(now));
            pwr.flush();
            response = is.readLine();
            System.out.println("Server Response : " + response);

            is.close();
            pwr.close();
            br.close();
            s1.close();
            System.out.println("Connection Closed");

            JFrame f;

            f=new JFrame();
        TimeUnit.SECONDS.sleep(10);
        }

    }
}

那么,只是为了确认——您是否只看到一次输出,然后程序停止?您确定没有异常吗?是的,我只看到一次输出,而不是第二次,不应该有任何异常,因为ide中没有异常。但是如果有,我如何在ide之外的控制台中看到异常呢?(我试过cmd,但没有成功)