create a new windows (xp) service that runs a jar file

Discussion in 'Java' started by JPractitioner, Jul 5, 2006.

  1. Hello guys,

    Does anyone has experience/know how to create a new windows (xp)
    service that runs a jar file? This issue rises as i need to hide the
    most of the java implementation in this project before it goes live.

    So the idea is, to have control on the exceution of the jar from
    windows windows service console (which the users can define the startup
    type i.e. manual, automatic, disabled and the running life cycle i.e.
    start, stop, pause, resume, restart...).

    so any leads to solving this will be appreciated.

    Thanks in advance. Have a nice day!
     
    JPractitioner, Jul 5, 2006
    #1
    1. Advertising

  2. JPractitioner

    Guest

    JPractitioner wrote:
    > Hello guys,
    >
    > Does anyone has experience/know how to create a new windows (xp)
    > service that runs a jar file? This issue rises as i need to hide the
    > most of the java implementation in this project before it goes live.
    >
    > So the idea is, to have control on the exceution of the jar from
    > windows windows service console (which the users can define the startup
    > type i.e. manual, automatic, disabled and the running life cycle i.e.
    > start, stop, pause, resume, restart...).
    >
    > so any leads to solving this will be appreciated.
    >
    > Thanks in advance. Have a nice day!


    I imagine you would create it like any other windows service. See
    http://support.microsoft.com/kb/q137890/

    Regards,
    Daniel Sjöblom
     
    , Jul 5, 2006
    #2
    1. Advertising

  3. JPractitioner

    Real Gagnon Guest

    Real Gagnon, Jul 5, 2006
    #3
  4. thx to the both of u.
    i really appreciate..
    good luck and all the best!


    Real Gagnon wrote:
    > > Does anyone has experience/know how to create a new windows (xp)
    > > service that runs a jar file? This issue rises as i need to hide the
    > > most of the java implementation in this project before it goes live.

    >
    > Use the "Java Service Wrapper"
    >
    > http://wrapper.tanukisoftware.org/doc/english/introduction.html#service
    >
    > Bye.
    > --
    > Real Gagnon from Quebec, Canada
    > * Looking for Java or PB code examples ? Visit Real's How-to
    > * http://www.rgagnon.com/howto.html
     
    JPractitioner, Jul 7, 2006
    #4
  5. Hi Daniel, I followed your way.
    I just dont know how to start with java service wrapper. realgagnon
    might have some idea on this that he can share with us?

    So back to the topic, I managed to add a new service on my pc and it
    shows in my services applet. But the service cannot run a jar file, it
    throws error that says the service has been stopped because it is
    inactive. Actually the program is active. It listens to client's
    requests once started. It takes some configuration value from a few
    files.

    Anyway, i figured out that, windows might expect an exe instead of jar
    to execute. So i tried to convert the jar to exe. I did that and the
    exe can run. Following that, I edit my registry.. pointing the value
    data to the exe i made.

    I try again, this time i can see my program's console for a while and
    then my program throws error saying that it cannot get the file as if
    the file was not even there.

    This is weird since i can run the program perfectley with the jar and
    the exe but when it involves windows service to run the exe, the file
    not found error slap me right on my face.

    So, dsjoblom.. /other readers, do u have any idea why this happened and
    how i can solve this?

    Thinking of other alternatives, I will just copy a shortcut to my
    startup folder, but this wont do very well since someone (administrator
    in my case) has to log on before the system can run. The administrator
    account will have to log on forever... or I might have to consider
    another user account dedicated to this thing hmmmm......

    ok guys, thanks.

    wrote:
    > JPractitioner wrote:
    > > Hello guys,
    > >
    > > Does anyone has experience/know how to create a new windows (xp)
    > > service that runs a jar file? This issue rises as i need to hide the
    > > most of the java implementation in this project before it goes live.
    > >
    > > So the idea is, to have control on the exceution of the jar from
    > > windows windows service console (which the users can define the startup
    > > type i.e. manual, automatic, disabled and the running life cycle i.e.
    > > start, stop, pause, resume, restart...).
    > >
    > > so any leads to solving this will be appreciated.
    > >
    > > Thanks in advance. Have a nice day!

    >
    > I imagine you would create it like any other windows service. See
    > http://support.microsoft.com/kb/q137890/
    >
    > Regards,
    > Daniel Sjöblom
     
    JPractitioner, Jul 20, 2006
    #5
  6. guys, when i meant "files".. they are the configuration files that feed
    the configuration value such as remote address and so on...



    JPractitioner wrote:
    > Hi Daniel, I followed your way.
    > I just dont know how to start with java service wrapper. realgagnon
    > might have some idea on this that he can share with us?
    >
    > So back to the topic, I managed to add a new service on my pc and it
    > shows in my services applet. But the service cannot run a jar file, it
    > throws error that says the service has been stopped because it is
    > inactive. Actually the program is active. It listens to client's
    > requests once started. It takes some configuration value from a few
    > files.
    >
    > Anyway, i figured out that, windows might expect an exe instead of jar
    > to execute. So i tried to convert the jar to exe. I did that and the
    > exe can run. Following that, I edit my registry.. pointing the value
    > data to the exe i made.
    >
    > I try again, this time i can see my program's console for a while and
    > then my program throws error saying that it cannot get the file as if
    > the file was not even there.
    >
    > This is weird since i can run the program perfectley with the jar and
    > the exe but when it involves windows service to run the exe, the file
    > not found error slap me right on my face.
    >
    > So, dsjoblom.. /other readers, do u have any idea why this happened and
    > how i can solve this?
    >
    > Thinking of other alternatives, I will just copy a shortcut to my
    > startup folder, but this wont do very well since someone (administrator
    > in my case) has to log on before the system can run. The administrator
    > account will have to log on forever... or I might have to consider
    > another user account dedicated to this thing hmmmm......
    >
    > ok guys, thanks.
    >
    > wrote:
    > > JPractitioner wrote:
    > > > Hello guys,
    > > >
    > > > Does anyone has experience/know how to create a new windows (xp)
    > > > service that runs a jar file? This issue rises as i need to hide the
    > > > most of the java implementation in this project before it goes live.
    > > >
    > > > So the idea is, to have control on the exceution of the jar from
    > > > windows windows service console (which the users can define the startup
    > > > type i.e. manual, automatic, disabled and the running life cycle i.e.
    > > > start, stop, pause, resume, restart...).
    > > >
    > > > so any leads to solving this will be appreciated.
    > > >
    > > > Thanks in advance. Have a nice day!

    > >
    > > I imagine you would create it like any other windows service. See
    > > http://support.microsoft.com/kb/q137890/
    > >
    > > Regards,
    > > Daniel Sjöblom
     
    JPractitioner, Jul 20, 2006
    #6
  7. JPractitioner

    bowman Guest

    JPractitioner wrote:

    > I try again, this time i can see my program's console for a while and
    > then my program throws error saying that it cannot get the file as if
    > the file was not even there.


    Where is it looking for the file? Services inherit from the SCManager and
    often act as if the cwd is %WINDIR%\system32. I am not familiar with the
    Java wrapper and don't know what tweaking it might do as the process is
    spun up by the SCManager. If you are using a relative path, try an
    absolute.

    As a service is started, The SCManager expects feedback from the new thread
    on a timely basis saying "I'm still trying to get it together", "I'm good
    to go", and so forth and assumes it is not running if the reply isn't
    received, but the wrapper should be taking care of this housekeeping.




    ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
     
    bowman, Jul 20, 2006
    #7
  8. "JPractitioner" <> wrote in message
    news:...
    > Hello guys,
    >
    > Does anyone has experience/know how to create a new windows (xp)
    > service that runs a jar file? This issue rises as i need to hide the
    > most of the java implementation in this project before it goes live.
    >
    > So the idea is, to have control on the exceution of the jar from
    > windows windows service console (which the users can define the startup
    > type i.e. manual, automatic, disabled and the running life cycle i.e.
    > start, stop, pause, resume, restart...).
    >
    > so any leads to solving this will be appreciated.
    >
    > Thanks in advance. Have a nice day!
    >


    If you really need to run a Java program as a Windows Service you might want
    to natively compile it.

    I know excelsior Jet professional has a windows service native compilation
    option.

    (I think Jet is the only byte code to windows code converter that is still
    around and up to date.) There is a GNU byte code to Linux binary compiler.

    --
    LTP

    :)
     
    Luc The Perverse, Jul 20, 2006
    #8
  9. Hi bowman,
    After i read your comment, i realized that those file were refered
    relatively. So i changed them to an absolute path. and it
    <b>WORKS!!!!!</b>

    thanks man for teaching me this.

    however, some xml files were also out of reach.. and the error said
    that the xml cant be found in c:\windows\system32

    so i place the xml files there, and its working.

    I have one more question.. why is that when i stop the service, only
    srvany.exe being killed.. but my app still alive? and also if i kill my
    app, the srvany.exe still alive.. why is it like this?

    Again, thanks a lot bowman, the tips u gave is the key that i will use
    to learn more about windows.

    Thanks,
    Makmur.


    bowman wrote:
    > JPractitioner wrote:
    >
    > > I try again, this time i can see my program's console for a while and
    > > then my program throws error saying that it cannot get the file as if
    > > the file was not even there.

    >
    > Where is it looking for the file? Services inherit from the SCManager and
    > often act as if the cwd is %WINDIR%\system32. I am not familiar with the
    > Java wrapper and don't know what tweaking it might do as the process is
    > spun up by the SCManager. If you are using a relative path, try an
    > absolute.
    >
    > As a service is started, The SCManager expects feedback from the new thread
    > on a timely basis saying "I'm still trying to get it together", "I'm good
    > to go", and so forth and assumes it is not running if the reply isn't
    > received, but the wrapper should be taking care of this housekeeping.
    >
    >
    >
    >
    > ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    > http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    > ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
     
    JPractitioner, Jul 20, 2006
    #9
  10. Thanks Luc, I'll take a look of this software,,


    Luc The Perverse wrote:
    > I know excelsior Jet professional has a windows service native compilation
    > option.
    >
     
    JPractitioner, Jul 20, 2006
    #10
  11. JPractitioner

    bowman Guest

    JPractitioner wrote:

    > I have one more question.. why  is that when i stop the service, only
    > srvany.exe being killed.. but my app still alive? and also if i kill my
    > app, the srvany.exe still alive.. why is it like this?


    I don't use srvany so I am not positive, but I do not think srvany
    implements the stop event. In C/C++, you add code to the application. The
    SCManager calls that as main(), which sets up the dispatcher, usually
    ServiceMain() by convention. That threads off the real application, and
    also registers a callback with the SCManager.

    When the dispatch thread receives a stop event from the SCManager, it
    reports back that it is stopping the application, does something to make
    that happen, reports when it is stopped. I believe srvany spins up the
    application, and after that it's on its own. It is meant to be a quick and
    dirty way to make something into a service when you don't have source.

    It isn't necessary, but I usually play a few games in the code to get the
    process's cwd back to where it really is so I don't clutter up
    %WINDIR%\system32, but afaik srvany doesn't do this. Also, if things are
    set up so the application will drop a core if things go bad, that usually
    is in system32, too.

    You can do a lot of interesting things with services in C, but I have no
    idea how you would do it in Java, except maybe JNI magic.





    ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
     
    bowman, Jul 21, 2006
    #11
  12. JPractitioner

    Steve Sobol Guest

    bowman wrote:
    > You can do a lot of interesting things with services in C, but I have no
    > idea how you would do it in Java, except maybe JNI magic.


    http://wrapper.tanukisoftware.org

    and there are a couple other similar products.

    --
    Steve Sobol, Professional Geek ** Java/VB/VC/PHP/Perl ** Linux/*BSD/Windows
    Apple Valley, California PGP:0xE3AE35ED

    It's all fun and games until someone starts a bonfire in the living room.
     
    Steve Sobol, Jul 21, 2006
    #12
  13. i see.. so srvany is not the best way eh.
    bowman, seems like u are really into windows programming. I had some
    very basic knowledge with C/C++. I suppose to call ServiceMain(), i
    will have to include some header files, probably C headers. Can u tell
    me whats the header file i will have to use?
    Yeah i will use JNI with C headers. By the way, converting the JAR to
    EXE involves JNI. So i'll use the the headers appropriately with JNI to
    explore deeper on controlling native threads.

    Before this, I also tried to make the srvany to run a batch file that
    will call the jar file. Just wont work. Windows services only run exe
    files i guess.

    Thanks for your comments.



    bowman wrote:
    > JPractitioner wrote:
    >
    > > I have one more question.. why is that when i stop the service, only
    > > srvany.exe being killed.. but my app still alive? and also if i kill my
    > > app, the srvany.exe still alive.. why is it like this?

    >
    > I don't use srvany so I am not positive, but I do not think srvany
    > implements the stop event. In C/C++, you add code to the application. The
    > SCManager calls that as main(), which sets up the dispatcher, usually
    > ServiceMain() by convention. That threads off the real application, and
    > also registers a callback with the SCManager.
    >
    > When the dispatch thread receives a stop event from the SCManager, it
    > reports back that it is stopping the application, does something to make
    > that happen, reports when it is stopped. I believe srvany spins up the
    > application, and after that it's on its own. It is meant to be a quick and
    > dirty way to make something into a service when you don't have source.
    >
    > It isn't necessary, but I usually play a few games in the code to get the
    > process's cwd back to where it really is so I don't clutter up
    > %WINDIR%\system32, but afaik srvany doesn't do this. Also, if things are
    > set up so the application will drop a core if things go bad, that usually
    > is in system32, too.
    >
    > You can do a lot of interesting things with services in C, but I have no
    > idea how you would do it in Java, except maybe JNI magic.
    >
    >
    >
    >
    >
    > ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    > http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    > ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
     
    JPractitioner, Jul 21, 2006
    #13
  14. JPractitioner

    bowman Guest

    JPractitioner wrote:

    > I suppose to call ServiceMain(), i
    > will have to include some header files, probably C headers. Can u tell
    > me whats the header file i will have to use?


    It is declared in Winsvc.h, but you would probably have to start with
    Windows.h which may cause problems. I don't suppose you have DevStudio and
    the MSDN docs. It documents the StartServiceCtrlDispatcher,
    RegisterServiceCtrlHandler, SetServiceStatus, and all the other hoops you
    have to jump through. Lacking that, there should be an example someplace on
    the 'net; it's pretty much boilerplate code.

    ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
     
    bowman, Jul 21, 2006
    #14
  15. JPractitioner

    bowman Guest

    Steve Sobol wrote:

    > http://wrapper.tanukisoftware.org


    Looks pretty handy, especially the third method. Often an application
    running as a service should do some atexit cleanup and shutdown gracefully
    rather than get chopped off at the knees with a ^C.




    ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
     
    bowman, Jul 21, 2006
    #15
  16. Thanks a lot bowman =)


    bowman wrote:
    > JPractitioner wrote:
    >
    > > I suppose to call ServiceMain(), i
    > > will have to include some header files, probably C headers. Can u tell
    > > me whats the header file i will have to use?

    >
    > It is declared in Winsvc.h, but you would probably have to start with
    > Windows.h which may cause problems. I don't suppose you have DevStudio and
    > the MSDN docs. It documents the StartServiceCtrlDispatcher,
    > RegisterServiceCtrlHandler, SetServiceStatus, and all the other hoops you
    > have to jump through. Lacking that, there should be an example someplace on
    > the 'net; it's pretty much boilerplate code.
    >
    > ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    > http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    > ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
     
    JPractitioner, Jul 21, 2006
    #16
  17. JPractitioner

    liquid

    Joined:
    Mar 28, 2007
    Messages:
    1
    JPractitioner

    Hello,

    I wanted to ask JPractitioner to make a post summarizing the steps he took to achieve his goal (run JAR as windows service) I'm trying to do the same thing here. Your help would be greatly appreciated.
     
    liquid, Mar 28, 2007
    #17
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Arnold Peters
    Replies:
    0
    Views:
    614
    Arnold Peters
    Jan 5, 2005
  2. muttley
    Replies:
    0
    Views:
    2,767
    muttley
    Oct 20, 2005
  3. puzzlecracker
    Replies:
    2
    Views:
    5,176
    Jean-Francois Briere
    Dec 20, 2005
  4. cyberco
    Replies:
    4
    Views:
    3,847
    Roedy Green
    Feb 14, 2006
  5. Arnold Peters
    Replies:
    0
    Views:
    690
    Arnold Peters
    Jan 5, 2005
Loading...

Share This Page