### Running as a Windows Service

A tool is provided to assist you in installing JReport Enterprise Server as a Windows Service. This tool JRservice.exe can be found in `<install_root>\bin`.

You will get the following information if you run JRservice.exe without any options:

    Usage:

    JRService -install [-interactive] to install the service
    JRService -remove                 to remove the service

        -interactive to enable JReport Enterprise Server service
                     to interact with the desktop

    StartServiceCtrlDispatcher being called.
    This may take several seconds. Please wait.

- JRService -install
  Running JRservice.exe with the -install option will install JReport Enterprise Server as a Windows Service. If you open the Services item in the Control Panel, you will find a service named JReport Enterprise Server in the list.
- JRService -install -interactive
  If you use the -interactive option together with -install, the service installed will be run in interactive mode. That is, when you start the service, a Command Prompt Window will pop up. However, if you don't specify this option when you install the service, the Command Prompt Window will not be displayed on the window when you start the service. After you have installed JReport Enterprise Server as a service, you will then be prompted to re-start your computer for the service installation to take effect.
- JRService -remove
  Running JRservice.exe with -remove option removes the Windows service of JReport Enterprise Server from Windows. However, before you run this, you should stop the service.

#### Configuring JReport Enterprise Server service

The parameters for the Windows service of JReport Enterprise Server are read from the file NTService.ini in `<install_root>\bin.`

In this file you will find three parameters specified, as shown in the following example:

    JavaVM="C:\jdk1.4\jre\bin\java.exe"
    StartArg= "-Dinstall.root=C:\JReport\Server"
    -classpath "C:\JReport\Server\lib\JREntServer.jar;
    C:\JReport\Server\lib\JREngine.jar;C:\JReport\Server\lib\servlet.jar;C:\TEMP"...
    -Djava.compiler=NONE -Dreporthome=C:\JReport\Server jet.server.JREntServer
    ShutdownArg= "-Dinstall.root=C:\JReport\Server"
    -classpath "C:\JReport\Server\lib\JREntServer.jar;
    C:\JReport\Server\lib\JREngine.jar;C:\JReport\Server\lib\servlet.jar;C:\TEMP" ...
    -Djava.compiler=NONE
    -Dreporthome=C:\JReport\Server jet.server.CommandSender localshutdown

- JavaVM
  The path of the Java VM.
- StartArg
  The Java command line for launching JReport Enterprise Server as an independent web application server. This will be called when the service is started.
- ShutdownArg
  The Java command line for shutting down JReport Enterprise Server. This is called when the service is stopped.

#### Starting the service

There are two ways to start the JReport Enterprise Server service.

- After the server has been installed as a service, it is by default configured to start automatically each time. In other words, without otherwise modifying the Control Panel, the service will start automatically each time Windows is started.
- You can directly start the service through the Services item in the Control Panel. Open the Services list, find JReport Enterprise Server on the list, select it and click the Start button.

You can change the options in the file NTService.ini in `<install_root>\bin` before you start the service. In the example above, there are no options specified in StartArg. If you would like to set all error log levels to WARN and trace log levels to INFO, you will need to append -logall at the end, as in the following example:

    ...
    StartArg= "-Dinstall.root=C:\JReport\Server"
    -classpath "C:\JReport\Server\lib\JREntServer.jar;
    C:\JReport\Server\lib\JREngine.jar;C:\JReport\Server\lib\servlet.jar;
    C:\JReport\Server\lib\log4j-1.2.8.jar;C:\TEMP" -Djava.compiler=NONE
    -Dreporthome=C:\JReport\Server jet.server.JREntServer -logall
    ...

Reference: For more information on the options available, see Starting JReport Enterprise Server using Java.

#### Stopping the service

There are three ways for you to stop the JReport Enterprise Server service:

- Open the Control Panel, go to Administrative Tools, double-click the Services item, select JReport Enterprise Server, and then click the Stop button if it is not disabled.
- Run the batch file CmdSender.bat in `<install_root>\bin` with the localshutdown argument, for example: `<install_root>\bin\CmdSender.bat localshutdown`.
- Use the Shut Down the Server button on the JReport Administration page.

Notes:

- All ODBC data sources used by the JREntSrv Service belong to the System DSN. System data sources can be used by all users on a computer, and are visible to all users on the computer and system-wide services, such as Microsoft Windows services. User data sources can only be used by the current user and are visible only to that user. To establish JReport Enterprise Server as a service, you should choose System Data Source. That is, define the data source in the System DSN. To do this, open Data Source (ODBC) in Control Panel, and add the data source used by JReport Enterprise Server to the System DSN panel. Also, remove any old ones from the User DSN.
- When using NT service to start JReport Enterprise Server, the mapped disk in path cannot be accessed due to JVM limitation. You should use UNC path (e.g. \\127.0.0.1\public_write) instead of the mapped disk it is mapped to (e.g. Z).