Usually, Java applications are run in a terminal on Unix systems. This requires a user account to be logged on to the system at all times and a terminal to be open.
There are several drawbacks to this ranging from security, to system performance, to simply having the risk of a user pressing the wrong key on the terminal and killing the Java application.
The Java Service Wrapper addresses these issues by making it possible to install your Java application as a daemon. It offers automatic detection of the service management tools (also known as init systems) available on your OS, or lets you configure a specific system to use when launching your application as a daemon.
Are you using Windows? Please check our QNA for Windows.
- What is a daemon?
- Simple HelloWorldServer Java Class
- Running HelloWorldServer in a terminal
- Running HelloWorldServer as a daemon
What is a daemon? |
UNIX daemon are similar to Windows Services. They allow you to run your application in the background and are automatically launched on system startup. The problem is that Java on its own cannot be run as a daemon. The user doing something as simple as logging off the machine will cause Java to shutdown. The Java Service Wrapper not only makes it possible, but makes it easy to run any Java application as a daemon. It also adds advanced failover, error recovery, and analysis features to make sure that your application has the maximum possible uptime. |
Simple HelloWorldServer Java Class |
|||||||||||||||||||||||||
For this example, we will be making use of a simple HelloWorldServer application that will run in the background. Please take a look at the full overview of the application to learn how to create and build the HelloWorldServer application for this example.
|
Running HelloWorldServer in a terminal |
||||
The Wrapper has now been set up. Let's start testing our configuration by running the Wrapper in the terminal. Please open a new terminal and go into our $(EXAMPLE_HOME) directory with the cd command. The Wrapper and our wrapped application can now be started as follows:
Note that the location of the configuration file is relative to the location of the Wrapper binary. This is a little counter-intuitive, but it greatly increases the reliability of the Wrapper when launched using different methods. You should see something similar to the below output after the Wrapper starts:
The banner at the top of the log is because we are using a temporary trial license. It points you to where you can get a long term trial license or purchase a license later.
The lines following "Java Command Line:" show all arguments of the command that the Wrapper uses to launch the JVM.
It is very useful to resolve problems.
Once it is working, please comment out the
wrapper. If you have purchased a license, this is what you would see:
You can stop your application at any time by pressing CTRL-C. The Wrapper always keeps a record of why an application was stopped so you will see something like the following in your log.
|
Running HelloWorldServer as a daemon |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Once the Wrapper configuration has been verified as correct, we are ready to install the Wrapper as a daemon.
|
Reference: Launching your application with the Wrapper |
[Windows] [Linux / Unix]
[Common] |