2

Given the source code of a Java application with a GUI

when I compile it and invoke it from the command line

then I would like it to run the GUI and detach from the console it was invoked on, so I could resume typing there.

How can I modify the source code to achieve this?

An example of this behaviour - though not a Java program - would be ReKonq.

Note: I want to achieve this independent of the OS, i.e. I do not want to change the way I invoke it, but modify my public static von main(String[] args) method.

arney
  • 795
  • 7
  • 20
  • 1
    Possible duplicate of [How to run process as background and never die?](http://stackoverflow.com/questions/4797050/how-to-run-process-as-background-and-never-die) – sinclair Mar 11 '16 at 12:04
  • @sinclair No, this is not about OS tools (like `nohup`), but about achieving this OS-independent in the Java source. – arney Mar 11 '16 at 12:06
  • 3
    This is not built into the Java runtime, so you need to either do it from the launching process ("shell" /"cmd") or talk to the operating system if you want to do it from Java itself. – Thorbjørn Ravn Andersen Mar 11 '16 at 12:06

2 Answers2

4

You can launch it from the command line with a & at the end of the line to run it in background :

java MyApplication &

If it is already launched, you can press ctrl + z and then type bg to get the same result.

(Assuming your are on Linux)

Benjamin
  • 3,350
  • 4
  • 24
  • 49
0

I don't think you can achieve this with pure Java, because in the end Java is just another process to the operating system you're on. As you want to avoid OS specific details, you may consider using a Java service wrapper. Some Apache software too use this, one that I'm aware of is this service wrapper.

Bunti
  • 1,730
  • 16
  • 20