Java daemon deployment

2019-04-15 00:20发布

问题:

I have a console Java application, which runs all the time on a remote server (nohup java -jar myapp.jar &).

Frequently (every other day) I need to replace the JAR file by a newer one (whenever I fix a defect).

At the moment I do this by connecting to the server using ssh (WinSCP).

How can I create a mechanism, using which I could upgrade the application via the http protocol? Can I use JMX for that?

That mechanism should do following things:

a) Stop the currently running application.

b) Upload the new JAR file to the server.

c) Launch the new JAR file.

回答1:

Basically you need to break down the program into two parts:

  1. the monitor component which fetches the new jar, stops the program, replaces the jar, restarts the program

  2. the actual program, the console java application

Theoretically you can do all of this in a single java process but the additional complexity is not worth the trouble in my opinion.



回答2:

You might check out install4j or this similar StackOverflow question.



回答3:

In LiveRebel, there's native support for standalone applications (i.e. daemons). So the main application is running with the watchdog agent which communicates to the command center. From command center it is possible then to manage the updates.



标签: java daemon jmx