Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to start a Java Runtime Image with prunsrv using jvm mode?

Background: Since Java 9 it is possible to create custom runtime images (JRE+program) using jlink.

It is possible to install Java programs as Windows service using prunsrv.exe (part of Apache Commons Daemon).

prunsrv can be used in three start modes: java, jvm and exe.

I managed to start a custom runtime image using the exe mode and a traditional Java program (classpath + normal JDK) using jvm mode, but I was not able to use the jvm mode (which doesn't start a new process) with the image.

prunsrv has a "JvmOptions9" parameter, which could be a hint that this scenario may be supported, but I am not sure.

like image 949
Gustave Avatar asked Nov 06 '22 15:11

Gustave


1 Answers

I had the same issue at first, but managed to solve it. While this is an old issue it was the first I found when I searched, so I will provide my answer for others.

I could install the service without problems, but when I tried to start it in jvm mode it would fail and complain that "%1 is not a valid Win32 application". The keyword here is Win32.

There are two versions of the prunsrv executable: one in the installation directory and one in the amd64 subdirectory. The version in the installation directory only supports 32 bit, while the one in amd64 is for 64 bit code. The prunsrv and the Java version must both be 32 bit or 64 bit; I was trying to start a 64 bit Java VM from a 32 bit prunsrv service.

In other words, make sure that the correct version of prunsrv for the intended Java VM is used. With that I can run a modular Java 9 (or actually 12) application with a stripped down runtime image without problems.

like image 67
ewramner Avatar answered Nov 17 '22 07:11

ewramner