Running the Java side as a service
How can I run the Java side as a service? I'd like to have it start when the machine starts, and I'd like it to be running even when nobody's logged on.
The easiest way to run the Java side as a service is to use the open-source Java Service Wrapper, by Tanuki Software (http://wrapper.tanukisoftware.org). This wrapper allows a Java program to run as a Windows service. (It can also be used to create Unix or Linux services.) To set up the Java side as a service, download the Java Service Wrapper and unpack it. The following instructions assume the use of Java Service Wrapper 3.3.0. For other versions, please consult the documentation for possible changes. Assume that %WRAPPER_HOME% denotes the base folder containing the Java Service Wrapper.
Navigate to %WRAPPER_HOME%conf, and open wrapper.conf in a text editor. Make the following changes to wrapper.conf:
1. Edit wrapper.java.mainclass so that it reads
2. After the property wrapper.java.classpath.2, add the folders and jar files to be used by the Java side. For example:
wrapper.java.classpath.3=C:/Program Files/JNBridgePro v4.0/jnbcore/jnbcore.jar
and so on.
3. Edit wrapper.app.parameter.1 so that it reads
4. Add additional wrapper.app.parameter properties, starting with 2, to reflect the additional command-line parameters that should be used to start up the Java side. Make sure each token is its own parameter. For example, you could write:
wrapper.app.parameter.3="C:/Program Files/JNBridgePro v4.0/jnbcore/jnbcore_tcp.properties"
5. Edit wrapper.ntservice.name, wrapper.ntservice.displayname, and wrapper.ntservice.description to contain the name of the service and descriptive information.
Save wrapper.conf away once the changes have been made.
Test the configuration by opening a command-line window and navigating to %WRAPPER_HOME%bin. Run TestWrapper.bat. You should see the typical Java-side output in the window. Terminate the test by typing control-C. If the behavior wasn't correct, change wrapper.conf and try again.
Once you're confident that wrapper.conf is correct and TestWrapper.bat works, run InstallTestWrapper-NT.bat from %WRAPPER_HOME%bin. This will install the service. Now, open the Services control panel and start the service. Configure it to Automatic or Manual as necessary. You now have a service that runs the JNBridgePro Java side.
Note: An alternative approach that we do not recommend is to create a Windows Service using Visual Studio.NET and have the service start up the Java side in a new Java process. The problem with this approach is that although the service will start up the Java side, if someone logs off while the Java side is running, Windows will kill the Java process, although the service itself will keep running. The Java Service Wrapper will avoid this behavior by catching the kill signals sent by Windows before they reach the Java process.