0

I got this gui which has 2 buttons start and stop server When I press start the server needs to start running and if i close the GUI it should have no effect on the running of the server the server will only be stopped if i open the gui and press stop server What is the best way to do so? I was thinking about creating a new console application, but i have no idea how to do so while running a program.

This is what i tried:

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            Runtime runTime = Runtime.getRuntime();
            try {
                Process process = runTime.exec("java -classpath .\\bin Server.RunServer");

            } catch (IOException e) {

                e.printStackTrace();
            }
Martin G
  • 17,357
  • 9
  • 82
  • 98
2D3D
  • 353
  • 1
  • 6
  • 22
  • are you using Swing? – Safwan Hijazi Jun 07 '15 at 18:43
  • no i use swt but thats not the main problem the thing is how you do something like i mentioned above – 2D3D Jun 07 '15 at 18:52
  • Here is question with pretty much same issues: http://stackoverflow.com/questions/29820672/can-i-create-java-gui-application-which-can-run-other-java-programs-in-it/29822060#29822060 – John Jun 07 '15 at 18:53
  • possible duplicate of [How do I launch a completely independent process from a Java program?](http://stackoverflow.com/questions/931536/how-do-i-launch-a-completely-independent-process-from-a-java-program) – RealSkeptic Jun 07 '15 at 18:53
  • That answers shows sort of 'deprecated' way to achieve this with Runtime.exe – John Jun 07 '15 at 18:55
  • It wont seem to help me those example even the process builder – 2D3D Jun 07 '15 at 18:57
  • you are not using processbuilder correctly in your question. – John Jun 07 '15 at 18:58
  • what do you mean I tried something like this ProcessBuilder pb = new ProcessBuilder("java.exe","-cp","bin","Server.RunServer"); try { Process process = pb.start(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } – 2D3D Jun 07 '15 at 18:59
  • no i rather not do so because i want to always change it and keep it as so . is the only way is to make it a jar file? – 2D3D Jun 07 '15 at 19:02
  • Does Server.RunServer include main method ? – John Jun 07 '15 at 19:02
  • yes it does contain a main class but when i run the code it wont seem to do something – 2D3D Jun 07 '15 at 19:03
  • Have you set JAVA_HOME environment variable ? Could you try to write full path to Server.RunServer – John Jun 07 '15 at 19:10
  • When saying full path you mean something like:C:\Users\Akok\61\Playground\src\Server\ServerWindow.java – 2D3D Jun 07 '15 at 19:14
  • i meant full path to external application you are trying to execute with process builder. Yeah, in that form – John Jun 07 '15 at 19:17
  • my friend,can you please help me write the correct code? The file is RunServer it is in Server package and the path is as specified above – 2D3D Jun 07 '15 at 19:19

0 Answers0