Search code examples
javauser-interfaceserverclient

How to run GUI from Server with Client


Hello guys i made Battleship GUI on the Server, i can connect with the client but how can i run the GUI Apllication which is on the server with the client ?

Dont know how to tackle this problem


Solution

  • The client needs to download the GUI Application as a jar file and then run it.

        URL website = new URL("http://www.mywebsite.com/gui-application.jar");
        Path path = Paths.get("gui-application.jar");
        try (InputStream in = website.openStream()) {
            Files.copy(in, path, StandardCopyOption.REPLACE_EXISTING);
        }
    
        ProcessBuilder processBuilder = new ProcessBuilder("java", "-jar", path.toAbsolutePath().toString());
        Process guiApplication = processBuilder.start();