javaeclipsebatch-filewindows-servicesnssm

Registering Eclipse Headless build as Windows Service


I currently developed an Eclipse application which also has a headless build available to integrate with some other application. We created a .exe for our application. What I need is when the installation of our application is completed the headless build should be register as window service. The headless build is started using a batch file which contains following :

set WORKSPACE=
java -jar plugins/org.eclipse.equinox.launcher_1.3.0.v20130327-1440.jar -pluginCustomization plugin_customization.ini -application myapplication.app.HEADLESSAPP -data %WORKSPACE% -noExit -isHeadLess

When we run this .bat file it starts our application in Non UI mode.

I tried following things so far:

  1. Tried sc.exe command but this didn't work.
  2. Then I converted my .bat file to .exe and then tried sc.exe(give error 1053) and NSSM(executable path always refer to nssm.exe instead of my application).

So basically I need a way to to register this .bat or .exe file as windows service so that it launch my headless application.

UPDATE :

Tried this :

set SERVICE_NAME=TESTSERVICE
set SERVICE_TITLE="TESTSERVICE"

set ECLIPSE_DIR=%~dp0

"%~dp0TESTSERVICE.exe" install %SERVICE_TITLE% --Startup=auto --StartMode=java --StartImage="%ECLIPSE_DIR%eclipsec.exe" --StartPath="%ECLIPSE_DIR%\" ++StartParams="-noSplash -pluginCustomization plugin_customization.ini -application com.eu.ales.hvac.ipm.headless.app.HEADLESSIPMDT -data \"%ECLIPSE_DIR%workspace\" -configuration \"%ECLIPSE_DIR%configuration\"" --LogPath="%ECLIPSE_DIR%\" --LogLevel="Error" --LogPrefix="service" 

but getting this

error


Solution

  • To run a headless Eclipse RCP application as Windows service I use successfully Apache Commons' prunsrv.exe (download here) for several years.

    Step-by-step instruction to run Eclipse Infocenter (which is a headless RCP application and contained in all Eclipse IDE packages) as Windows service:

    1. Preconditions:
    2. Download commons-daemon-1.0.15-bin-windows.zip from http://www.apache.org/dist/commons/daemon/binaries/windows/
    3. Extract prunsrv.exe from root directory of the downloaded ZIP archive into your Eclipse installation directory
    4. In the Eclipse installation directory create the file install_as_service.bat with following content:

      set INFOCENTER_PORT=8088
      set INFOCENTER_TITLE="Eclipse Infocenter"
      for %%i in ("%~dp0") do (set INFOCENTER_DIR=%%~dpi)
      set INFOCENTER_DESCRIPTION=Port: %INFOCENTER_PORT%, Location: %INFOCENTER_DIR%
      "%~dp0\prunsrv.exe" install %INFOCENTER_TITLE% --Description="%INFOCENTER_DESCRIPTION% " --Startup=auto --StartMode=exe --StartImage="%INFOCENTER_DIR%eclipsec.exe" --StartPath="%INFOCENTER_DIR%\" ++StartParams="-noSplash#-application#org.eclipse.help.base.infocenterApplication#-data#\"%INFOCENTER_DIR%info_center_workspace\"#-configuration#\"%INFOCENTER_DIR%info_center_configuration\"#-vmargs#-Dserver_port=%INFOCENTER_PORT%#-Xms420m#-Xmx420m#-XX:MaxPermSize=256m" --StopMode=exe --StopTimeout=300 --StopImage="%INFOCENTER_DIR%eclipsec.exe" --StopPath="%INFOCENTER_DIR%\" ++StopParams="-noSplash#-application#org.eclipse.help.base.infocenterApplication#-data#\"%INFOCENTER_DIR%info_center_workspace\"#-configuration#\"%INFOCENTER_DIR%info_center_configuration\""#-command#shutdown --LogPath="%INFOCENTER_DIR%\" --LogLevel="Error" --LogPrefix="service"
    5. Double-click install_as_service.bat

    6. Press Windows+R, enter services.msc and click OK
      • => The list of services should contain Eclipse Infocenter
    7. Start the service Eclipse Infocenter
    8. In a web browser open http://localhost:8088/help/index.jsp

    To uninstall the service, first stop the service and then run prunsrv.exe delete "Eclipse Infocenter"