0

I have a Java Application(works as server for a client application) with a GUI. This application has to run always even after restarts of the server.

I have created a windows service using Apache daemon for this purpose.

When the server starts I can see my services running as system service. But when I open the GUI of the application another instance starts.

I need the GUI to be attached to the same instance which started after restart, is this possible.

3
  • how do you open the GUI? by clicking the icon? Commented Sep 7, 2017 at 6:36
  • 1
    AFAIK services can't have GUIs - you will need the GUI to attach to the running service (via sockets for example) Commented Sep 7, 2017 at 6:37
  • Yes I am Trying to open GUI by clicking the icon Commented Sep 7, 2017 at 6:55

1 Answer 1

1

A Windows Service (as well as daemons on Unix-systems) can't run with a GUI because it starts without a Window Management System like Windows Desktop or KDE, Gnome, etc. I'm actually surprised that your application starts as a service because attempts to start GUI-elements should lead to an error.

You have to separate the GUI from the server components. The GUI then needs to communicate with the server by some protocol. Because you already have finished your application I suggest RMI as protocol of choice, that should be the easiest to implement because you essentially just have to add some interfaces to your classes to get RMI on its way instead of adding a complete layer of complexity by your own (an additional server to receive commands from the client, etc.).

RMI can be set up to only listen for connections from localhost, so in terms of security you should be good as well.

Sign up to request clarification or add additional context in comments.

2 Comments

On Windows, services are quite capable of creating GUI elements; they just can't interact with the user. Windows creates dummy display surfaces as necessary.
So in this case, is it possible to just start the GUI itself on restart, I understand that is possible through startup but that will need a user login to activate.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.