it may be easy or less, depending what you need to do when the
service receive the request to stop.
If you don't need this part, exist little programs as srvany.exe
) that can "trasform"
any executable in a service. In this case the executable will be
"JAVAW.EXE YourClassInAJar...", but I am not sure what happens
when the Service is stopped.
The right way, is to:
1) I built a normal Window Service, using Visual Studio or
what you prefere.
2) Test its mechanism, intercepting the Start and Stop Request
Until this point, we did not pronunce the Java "word".
3) Insert in the Start action routine, the run of:
"JAVA.EXE - YourJavaProgram", and everything will run fine,
and you'll see your Service in Started State.
4) What happens when the Service gets a Stop Request ? uhmmm !
You have to find a "talk" mechanism between tha Java code
and the C++ module, the one that handles this Stop Request.
A simple way, may be to use a file as semaphore: the C++ routine,
rather than kill the child process, can create such file.
If you want to run this Java program as a Service,
probably it will have a loop with a pause. Then, before sleeping, it could test the presence of such file: if it founds the semaphore, deletes it and perform a "hara-kiri":
it closes correctely the open handles (DB,files,sockets,...), and call a Java System.exit().
[You can use other mechanisms as sockets or other to syncrho
the twin, but you have time to complicate your life: do it later!]
The service will detect the child end
(if you run from command line, you'll see the prompt again)
and you'll see on the Service Manager, that your service wil be in stop state.
Probably you'd prefere "code": begin with the architecture,
then the code will arrive, also from others.