|
|
 |
 |
| Launching Your Application (Windows) |
Launching Your Application (Windows)
 |
|
|
 |
 |
 |
|
Setting up the scripts used to launch the Java Service Wrapper is extremely simple.
Simply copy the following 3 batch files from the Wrapper directory
into the bin directory of your application.
{WRAPPER_HOME}\src\bin\App.bat.in
{WRAPPER_HOME}\src\bin\InstallApp-NT.bat.in
{WRAPPER_HOME}\src\bin\UninstallApp-NT.bat.in
|
Rename the three batch files with reflecting your application name as follows.
(Replace "MyApp" with the name of your application throughout this document.)
Be sure to remove the .in extensions
so that the files all end in .bat.
(Depending on how your file explorer is configured on your computer,
you may not be able to see file extensions.)
C:\MyApp\bin\MyApp.bat
C:\MyApp\bin\InstallMyApp-NT.bat
C:\MyApp\bin\UninstallMyApp-NT.bat
|
The three batch files are used to run an application in a console,
and to install and remove it as a Windows Service.
These batch files should not require any modification.
They do assume that
the actual Wrapper executable file "wrapper.exe"
is placed in the same directory,
and also assume that
the wrapper.conf
file is placed within a conf directory
(one level up, ../conf/wrapper.conf).
If you wish to place either of these files somewhere else,
then the three batch files will require appropriate modification.
|
 |
 |
|
Start the application:
Running the application in a console (Command Window) can be done by
double clicking on the MyApp.bat batch file
from within the file explorer.
Or it can be also done by opening a Command Window and
then running the batch file from the command prompt.
Because of the way the Wrapper script sets its current directory,
it is not necessary to run this batch file from within the
bin directory.
C:\MyApp\bin>MyApp.bat
wrapper | --> Wrapper Started as Console
wrapper | Launching a JVM...
jvm 1 | Wrapper (Version 3.x.x)
jvm 1 |
|
Stop the application:
The application can be terminated
by pressing CTRL-C in the console (command window).
This will cause the Wrapper to shut down the application cleanly.
|
 |
 |
|
Before proceeding, please make sure you have configured all of the
Windows Service related properties in the
wrapper.conf
file.
You should also have verified that the application runs correctly in console mode.
Install as a Windows Service :
The application can be installed as a service by double clicking on
the InstallMyApp-NT.bat batch file
from within the file explorer.
Or by opening a Command Window and then running the install script from the command prompt.
If the service is installed successfully, the script will terminate immediately.
If there are any problems then an error message
describing what went wrong will be displayed.
The script will then wait for the user to press a key before terminating.
C:\MyApp\bin>InstallMyApp-NT.bat
wrapper | My Application installed.
|
Once the service has been installed,
it can be started by opening up the Service Control Panel
([Control Panel] - [Administrator Tool] - [Service]),
selecting the service, and then clicking the "start" button.
The service can also be started and stopped from within a Command Window
by using the net start MyApp
and net stop MyApp commands,
or by passing commands to
the wrapper.exe executable.
C:\MyApp\bin>net start MyApp
The My Application service is starting....
The My Application service was started successfully.
|
C:\MyApp\bin>net stop MyApp
The My Application service is stopping..
The My Application service was stopped successfully.
|
If the wrapper.ntservice.starttype
property is set to AUTO_START then the service will be started
whenever machine is rebooted.
Uninstall from the Windows Service :
The service can be uninstalled
by running the UninstallMyApp-NT.bat batch file.
C:\MyApp\bin>UninstallMyApp-NT.bat
wrapper | Service is running. Stopping it...
wrapper | Waiting to stop...
wrapper | My Application stopped.
wrapper | My Application removed.
|
|
 |
 |
|
As an alternative to using the scripts shipped with the Java Service Wrapper,
you may choose to launch the Wrapper directly.
If the wrapper.exe executable is launched
without any parameters, the following usage output will be displayed.
C:\MyApp\bin>wrapper.exe
Wrapper (Version 3.n.n) http://wrapper.tanukisoftware.org
Usage:
wrapper.exe <command> <configuration file> [configuration properties] [...]
wrapper.exe <configuration file> [configuration properties] [...]
(<command> implicitly '-c')
wrapper.exe <command>
(<configuration file> implicitly 'wrapper.conf')
wrapper.exe
(<command> implicitly '-c' and <configuration file> 'wrapper.conf')
where <command> can be one of:
-c --console run as a Console application
-t --start starT a Windows Service
-p --stop stoP a running Windows Service
-i --install Install as a Windows Service
-r --remove Remove as a Windows Service
-q --query Query the current status of the service
-qs --querysilent Silently Query the current status of the service
-? --help print this help message
<configuration file> is the wrapper.conf to use. Name must be absolute or relative
to the location of wrapper.exe
[configuration properties] are configuration name-value pairs which override values
in wrapper.conf. For example:
wrapper.debug=TRUE
|
To run the Wrapper as a console application,
you would specify the -c command,
followed by the
wrapper.conf file.
The location of the wrapper.conf file
can be an absolute or relative location.
If a relative path is used, the path is always relative to the location of the
wrapper.exe file, not the current directory.
C:\MyApp\bin>wrapper.exe -c ..\conf\wrapper.conf
|
To install the application as a Windows Service, execute:
C:\MyApp\bin>wrapper.exe -i ..\conf\wrapper.conf
|
Once installed, the service can be started just like any other Windows Service.
If the wrapper.ntservice.starttype
was set to AUTO_START when installed,
then the service will be started the next time the machine is rebooted.
It is also possible to start the service manually from the services control panel,
or by executing either of the following two commands:
C:\MyApp\bin>net start MyApp
C:\MyApp\bin>wrapper.exe -t ..\conf\wrapper.conf
|
|
NOTE
|  |
The net start x and
net stop x commands
have problems with services that take a long time to start or stop.
In most cases, they will work,
but if a service takes more than a few seconds to stop,
the net stop x command will return
that the service was stopped even though it is still in the process of stopping.
This can lead to problems
when a script must wait until a service has actually stopped before proceeding.
By using the Wrapper to start and stop the service,
you will be guaranteed not to have any such problems.
The Wrapper method of starting and stopping the service is also useful in scripts
as it does not require the actual name that
the service is installed as to exist anywhere except in the
wrapper.conf file.
This removes the need for manual editing of multiple files if the service name is changed.
|
The service can be stopped using the services control panel,
or by executing either of the following commands:
C:\MyApp\bin>net stop MyApp
C:\MyApp\bin>wrapper.exe -p ..\conf\wrapper.conf
|
To uninstall the application as a Windows Service, execute:
C:\MyApp\bin>wrapper.exe -r ..\conf\wrapper.conf
|
If the service is running at the time that it is uninstalled,
the service will be cleanly stopped and then removed.
|
 |
 |
|
The Wrapper can be used to query the state of the service manually or from within a batch file.
This can be useful for install scripts which need to know the current state of the service configuration.
C:\MyApp\bin>wrapper.exe -q ..\conf\wrapper.conf
wrapper | The My Application Service is installed.
wrapper | Start Type: Automatic
wrapper | Interactive: Yes
wrapper | Running: No
|
If run with the "-q" command,
the Wrapper will display the current status to the console,
"-qs" will run silently.
The Wrapper will then exit an exit code that is a combination of the following bits:
1 : Service is installed
2 : Service is running
4 : Service is interactive
8 : Start type is automatic
16 : Start type is manual
32 : Start type is disabled
|
An exit code of "15", for example, indicates that
the service is installed, running, interactive and configured to start automatically
when the system is booted.
An exit code of "0" (zero) means that the service is not currently installed.
|
 |
 |
|
The Wrapper also includes an alternative batch file which functions very much
like the shell script that is provided with Unix versions of the Wrapper.
This batch file requires a single command argument, which tells the batch file what to do.
It has the benefit of being able to do everything from a single batch file.
But the drawback of not being able to simply double-click on the batch file from the File Manager.
To make use of this batch file, simply copy the following file to your application's
bin directory.
{WRAPPER_HOME}\src\bin\AppCommand.bat.in
|
Rename the three batch files with refrecting your application name as follows.
(Replace "MyApp" with the name of your application throughout this document.)
Be sure to remove the .in extensions
so that the files all end in .bat.
(Depending on how your file explorer is configured on your computer,
you may not be able to see file extensions.)
To familiarize yourself with the script, run the batch file without any arguments.
You will see the following:
C:\MyApp\bin>MyApp.bat
Usage: MyApp.bat { console : start : stop : restart : install : remove }
Press any key to continue . . .
|
The console command runs the Wrapper in the current command window.
The start and stop
commands are used to start and stop the Wrapper when it is installed as a Windows Service.
The restart command will stop
and then immediately start the Wrapper.
And the install and remove
commands are used to install and remove the Wrapper as a Windows Service.
There are a few differences between this batch file for Windows and the Unix script.
The Unix script can be used to stop the Wrapper running in a console;
however, it is not possible to do so with the batch file for Windows.
In addition, the dump command is missing
from the batch file for Windows.
As an example, the Wrapper can be started in a console using the following command:
C:\MyApp\bin>MyApp.bat console
wrapper | --> Wrapper Started as Console
wrapper | Launching a JVM...
jvm 1 | Wrapper (Version 3.x.x)
jvm 1 |
|
To execute other commands, simply replace console
with the command you wish to have executed.
|
|
|
|
 | If you notice something that is incorrect, missing, or simply feel that some part of this page could be explained better, feel free to log in and add a comment. You will need to register before you can log on. |
|
|  |
|
 |
| |