Run multiple java main methods in eclipse

后端 未结 5 1572
天涯浪人
天涯浪人 2020-12-31 07:22

I\'m running Eclipse 3.5 and I have a frequent problem that in order to test my program, I have to do about 6-7 clicks as opposed to one click on the play button.

Th

5条回答
  •  自闭症患者
    2020-12-31 07:49

    Just to complete the validated answer: If you want to execute server and clients in parallel, you need to start a new thread for each client and server instance. You can do this as follow:

    pulic class Test_ServerClient {
        public static void main(final String[] args) {
    
            Thread serverThread = new Thread() {
                public void run() {
                    Server.main(args);
                }
            };
    
            Thread clientThread = new Thread() {
                public void run() {
                    Client.main(args);
                }
            };
    
            serverThread.start();
    
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
    
            clientThread.start();
        }
    }
    
    public class Server {
        public static void main(final String[] args) {...}
    }
    
    public class Client {
        public static void main(final String[] args) {...}
    }
    

提交回复
热议问题