Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Windows Service in Java?

Windows Service in Java?

Windows Service in Java?

Does anyone know if you can get Java code to run as a Windows Service?

How about as a Windows Control Panel plug-in?


RE: Windows Service in Java?

Sure, you can use any executable as a Windows service.


RE: Windows Service in Java?


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
(http://support.microsoft.com/kb/137890) 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.



Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close