procrunapache-commons-daemonprunsrv

Apache Commons Daemon (prunsrv) problems in JDK17


Good morning,

Before JDK17 I had a working setup to use prunsrv in Windows to start a Java app as a service.
Now I tried the same in JDK17 and I got errors. I could make some progress but now I am stuck with the latest error I got:

The system cannot find the file specified.

I use the latest 64bit Apache Commons Daeamon, my batch file is

SET J_HOME=%JAVA_HOME%
SET VERSION=1.2-SNAPSHOT
SET NAME=reaction-worker-executor-daemon
SET mypath=%~dp0
SET BASE_FOLDER=%mypath:~0,-1%
SET LIB_PATH=%BASE_FOLDER%/lib
SET CLASS_PATH=
FOR /R ./lib %%a in (*.jar) DO CALL :AddToPath %%a
SET CLASS_PATH=%CLASS_PATH%%BASE_FOLDER%\conf;%BASE_FOLDER%\security
SET CLASS_PATH=%BASE_FOLDER%\lib\reaction-worker-1.2-SNAPSHOT.jar;%BASE_FOLDER%\lib\reaction-common-1.2-SNAPSHOT.jar
SET CLASS=org.reaction.worker.DaemonLauncer
SET LOG_PATH=%BASE_FOLDER%/logs
SET LOG_OUT=%LOG_PATH%/%NAME%.out
SET LOG_ERROR=%LOG_PATH%/%NAME%.err
SET EXEC=%BASE_FOLDER%/reaction-worker-executor-daemon.exe
SET STARTUP_MODE=manual
IF "%1" == "install" (
    ECHO Installing the %DESC% ...
    %EXEC% install %NAME% --Install=%EXEC% --DisplayName=%NAME% --Jvm=auto --StartMode=jvm --StartClass=%CLASS% --StartMethod=startWindowService --StartParams=executor --StopMode=jvm --StopClass=org.reaction.worker.DaemonLauncer --StopMethod=stopWindowService --StopParams=executor ++Environment="BASE_FOLDER=%BASE_FOLDER%" --JvmOptions="-Dapp.home=%BASE_FOLDER%" ++JvmOptions="--add-opens java.base/java.lang=ALL-UNNAMED" --LogPrefix=%NAME% --LogPath="%LOG_PATH%" --StdError="%LOG_ERROR%" --StdOutput="%LOG_OUT%" --JavaHome=%J_HOME% --Startup=%STARTUP_MODE% --LogLevel=Trace
) ELSE IF "%1" == "deinstall" (
    ECHO Deinstalling the %DESC% ...
    %EXEC% delete %NAME%
) ELSE IF "%1" == "start" (
    ECHO Starting the %DESC% ...
    %EXEC% start %NAME%
) ELSE IF "%1" == "stop" (
    ECHO Stopping the %DESC% ...
    %EXEC% stop %NAME%
) ELSE (
    ECHO Usage: reaction_executor.bat {install^|deinstall^|start^|stop}
)
GOTO :EOF

:AddToPath
SET CLASS_PATH=%1;%CLASS_PATH%
GOTO :EOF

and the error:

[2023-03-20 00:09:12] [debug] ( prunsrv.c:1954:main                       ) [17604] Apache Commons Daemon procrun log initialized.
[2023-03-20 00:09:12] [info]  ( prunsrv.c:1958:main                       ) [17604] Apache Commons Daemon procrun (1.3.0.0 64-bit) started.
[2023-03-20 00:09:12] [info]  ( prunsrv.c:945 :docmdStartService          ) [17604] Starting service 'reaction-worker-executor-daemon'...
[2023-03-20 00:09:12] [warn]  (registry.c:878 :apxGetServiceDescriptionW  ) [17604] Can't read service description because registry key 'S' cannot query value at 'D' (rc = 2)
[2023-03-20 00:09:12] [warn]  ( service.c:159 :apxServiceOpen             ) [17604] Failed to obtain service description for 'r'
[2023-03-20 00:09:12] [debug] ( prunsrv.c:1954:main                       ) [ 6392] Apache Commons Daemon procrun log initialized.
[2023-03-20 00:09:12] [info]  ( prunsrv.c:1958:main                       ) [ 6392] Apache Commons Daemon procrun (1.3.0.0 64-bit) started.
[2023-03-20 00:09:12] [info]  ( prunsrv.c:1868:docmdRunService            ) [ 6392] Running Service 'reaction-worker-executor-daemon'...
[2023-03-20 00:09:12] [debug] ( prunsrv.c:1639:serviceMain                ) [15968] Inside serviceMain()...
[2023-03-20 00:09:12] [debug] ( prunsrv.c:1087:reportServiceStatusE       ) [15968] reportServiceStatusE: dwCurrentState = 2 (SERVICE_START_PENDING), dwWin32ExitCode = 0, dwWaitHint = 3000 milliseconds, dwServiceSpecificExitCode = 0.
[2023-03-20 00:09:12] [info]  ( prunsrv.c:1386:serviceStart               ) [15968] Starting service...
[2023-03-20 00:09:12] [debug] ( prunsrv.c:497 :setInprocEnvironmentOptions) [15968] Checking Java options for environment variable requirements
[2023-03-20 00:09:12] [debug] ( prunsrv.c:501 :setInprocEnvironmentOptions) [15968] Checking environment variable requirements for '-Dapp.home=C:\work\reaction\tmp\reaction-worker-1.2-SNAPSHOT'
[2023-03-20 00:09:12] [debug] ( prunsrv.c:501 :setInprocEnvironmentOptions) [15968] Checking environment variable requirements for '--add-opens java.base/java.lang=ALL-UNNAMED'
[2023-03-20 00:09:12] [debug] ( javajni.c:221 :__apxLoadJvmDll            ) [15968] No explicit RuntimeLib specified. Checking registry. Found ''
[2023-03-20 00:09:12] [debug] ( javajni.c:235 :__apxLoadJvmDll            ) [15968] Invalid RuntimeLib '', Checking registry for JRE home. None found.
[2023-03-20 00:09:12] [debug] ( javajni.c:244 :__apxLoadJvmDll            ) [15968] Using explicitly configured JavaHome 'c:\OpenJDK\jdk-17.0.2'
[2023-03-20 00:09:12] [debug] ( javajni.c:280 :__apxLoadJvmDll            ) [15968] Adding Java bin path to the PATH to fix loading of awt.dll: 'c:\OpenJDK\jdk-17.0.2\bin'
[2023-03-20 00:09:12] [debug] ( javajni.c:286 :__apxLoadJvmDll            ) [15968] Loading JVM DLL 'c:\OpenJDK\jdk-17.0.2\bin\server\jvm.dll'
[2023-03-20 00:09:12] [debug] ( javajni.c:414 :apxCreateJava              ) [15968] Loaded JVM DLL '', home 'c:\OpenJDK\jdk-17.0.2'.
[2023-03-20 00:09:12] [debug] ( javajni.c:419 :apxCreateJava              ) [15968] JNI_GetCreatedJavaVMs...
[2023-03-20 00:09:12] [debug] ( javajni.c:817 :apxJavaInitialize          ) [ 7840] JVM Option[0] -Dapp.home=C:\work\reaction\tmp\reaction-worker-1.2-SNAPSHOT
[2023-03-20 00:09:12] [debug] ( javajni.c:817 :apxJavaInitialize          ) [ 7840] JVM Option[1] --add-opens java.base/java.lang=ALL-UNNAMED
[2023-03-20 00:09:12] [debug] ( javajni.c:817 :apxJavaInitialize          ) [ 7840] JVM Option[2] exit
[2023-03-20 00:09:12] [debug] ( javajni.c:817 :apxJavaInitialize          ) [ 7840] JVM Option[3] abort
[2023-03-20 00:09:12] [error] ( javajni.c:828 :apxJavaInitialize          ) [ 7840] CreateJavaVM Failed with error [-1]
[2023-03-20 00:09:12] [error] ( javajni.c:828 :apxJavaInitialize          ) [ 7840] The system cannot find the file specified.
[2023-03-20 00:09:12] [debug] ( javajni.c:1087:__apxJavaWorkerThread      ) [ 7840] Java worker thread finished : with status = 2
[2023-03-20 00:09:12] [error] ( prunsrv.c:1447:serviceStart               ) [15968] Failed to start Java
[2023-03-20 00:09:12] [error] ( prunsrv.c:1802:serviceMain                ) [15968] ServiceStart returned 4.
[2023-03-20 00:09:12] [debug] ( prunsrv.c:1087:reportServiceStatusE       ) [15968] reportServiceStatusE: dwCurrentState = 1 (SERVICE_STOPPED), dwWin32ExitCode = 1066, dwWaitHint = 0 milliseconds, dwServiceSpecificExitCode = 4.
[2023-03-20 00:09:12] [info]  ( prunsrv.c:1870:docmdRunService            ) [ 6392] Run service finished.
[2023-03-20 00:09:12] [info]  ( prunsrv.c:2042:main                       ) [ 6392] Apache Commons Daemon procrun finished.
[2023-03-20 00:09:13] [debug] ( service.c:573 :apxServiceControl          ) [17604] apxServiceControl(): Sleeping 1000 milliseconds
[2023-03-20 00:09:14] [debug] ( service.c:577 :apxServiceControl          ) [17604] apxServiceControl(): QueryServiceStatus OK
[2023-03-20 00:09:14] [error] ( service.c:586 :apxServiceControl          ) [17604] apxServiceControl(): dwState(4 = SERVICE_RUNNING) != dwCurrentState(1 = SERVICE_STOPPED); dwWin32ExitCode = 1066, dwWaitHint = 0 millseconds, dwServiceSpecificExitCode = 4
[2023-03-20 00:09:14] [error] ( service.c:602 :apxServiceControl          ) [17604] apxServiceControl(): returning FALSE
[2023-03-20 00:09:14] [error] ( prunsrv.c:966 :docmdStartService          ) [17604] Failed to start service 'reaction-worker-executor-daemon'.
[2023-03-20 00:09:14] [info]  ( prunsrv.c:974 :docmdStartService          ) [17604] Finished starting service 'reaction-worker-executor-daemon', returning 0.
[2023-03-20 00:09:14] [error] ( prunsrv.c:2033:main                       ) [17604] Apache Commons Daemon procrun failed with exit value: 5 (failed to start service).

I'd appreciate any hint please!

Thanks a lot!


Solution

  • It is so frustrating when in the end it turns out that not the computer/Java/Apache Commons Daemon/etc. was at fault but me...

    So the problem was that I missed a '=' sign between the --add-opens and java.base/java.lang=ALL-UNNAMED. AFter I turned the --LogJniMessages on the relevant error message appeared in the log.

    Also I had to specifiy the --Classpath too explicitly.