Approach 1: Using “Yet Another Java Service Wrapper (YAJSW)”
Note:- License agreement of YAJSW is based on LGPL.
1.Download YAJSW from here
2. Un-zip the java wrapper. This creates several directories including a bat, conf directory.
3. Start your java application manually in Windows.
4. Note the Process Id of your java application from the Windows Task Manager.
5. Open command prompt and go to the bat directory under YAJSW installed path. Under it, run the batch file “genConfig.bat <Process Id of your java application>”. This will create “wrapper.conf” configuration file for you under the “conf” directory of YAJSW installed path.
6. Most of the contents in “wrapper.conf” file is automatically set by YAJSW for you during the Step 5 except for few which you can edit manually – “wrapper.ntservice.name”, “wrapper.ntservice.displayname” and “wrapper.ntservice.description”. Provide your service name with which your java application will be registered as windows service. Save your changes.
7. Stop your application which you started in Step 3.
8. Test if your application now starts properly through YAJSW by running the “runConsole.bat” script under the bat dir of YAJSW installed path. If everything is fine, then this script should start your application properly without any exceptions.
9. Incase of no errors/exceptions during Step 8, you can now register your application as windows service by running the script “installService.bat” under bat dir of YAJSW installed path.
10. Check in the windows “services” if your application is successfully added.
11. To start the service, execute the command “startService.bat”. Similarly to stop it, execute the command “stopService.bat”
12. If you want to de-register your java application as windows service, you can execute the command “uninstallService.bat”
3. Copy your jar, under the bin dir which got created in Step 1.
4. Edit the wrapper.conf directory under the conf directory which got created in step 1.
- Provide your main class name as value to “wrapper.java.mainclass”.
- Create an entry “wrapper.java.classpath.3” below ““wrapper.java.classpath.2″ and assign your jar name to “wrapper.java.classpath.3”.
- Un-comment “wrapper.app.parameter.1” and assign the complete class name of your main class along with the package name to it.
- Provide apt values to “wrapper.name”, “wrapper.displayname” and “wrapper.description”.Test if your application now works by running the “TestWrapper.bat” which is available under the bin directory of the java wrapper.
5. Test if your application now works by running the “TestWrapper.bat” which is available under the bin directory of the java wrapper.
6. If everything works fine, then you can now register your java application as windows service by simply running the command “InstallTestWrapper-NT.bat”.
7. Check in the windows “services” if your application is successfully added.
8. To start the service, execute the command “StartTestWrapper-NT.bat”. Similarly to stop it, execute the command “StopTestWrapper-NT.bat”.
9. If you want to de-register your java application as windows service, you can execute the command “UninstallTestWrapper-NT.bat”