简体   繁体   中英

Running java application as windows service

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM