1

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.

Glory to Russia
  • 17,289
  • 56
  • 182
  • 325
  • What OS does the server run? The hot-deploy mechanism you suggest sounds like a reasonable amount of work. If the server is running a POSIX OS perhaps it would be easier to script to sftp the file and then run some commands remotely via ssh in order to restart your server? You could incorporate the script directly into your build mechanism. – Adamski Oct 14 '11 at 11:41
  • The server is running on Ubuntu server. – Glory to Russia Oct 14 '11 at 11:43

3 Answers3

2

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.

Miserable Variable
  • 28,432
  • 15
  • 72
  • 133
  • 1
    Yes, I know that I can do it myself. However, if there are ready-made solutions for that, I'd like to use them. Don't want to re-invent the wheel :) – Glory to Russia Oct 14 '11 at 11:42
  • There is Java Web Start but it is more suitable for interactive applications, it checks for the latest version only at start-up. – Miserable Variable Oct 14 '11 at 11:44
0

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.

Anton Arhipov
  • 6,479
  • 1
  • 35
  • 43
0

You might check out install4j or this similar StackOverflow question.

Community
  • 1
  • 1
spork
  • 1,185
  • 1
  • 11
  • 17