Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > create a new windows (xp) service that runs a jar file

Reply
Thread Tools

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

 
 
bowman
Guest
Posts: n/a
 
      07-21-2006
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 =----
 
Reply With Quote
 
 
 
 
Steve Sobol
Guest
Posts: n/a
 
      07-21-2006
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.
 
Reply With Quote
 
 
 
 
JPractitioner
Guest
Posts: n/a
 
      07-21-2006
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 =----


 
Reply With Quote
 
bowman
Guest
Posts: n/a
 
      07-21-2006
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 =----
 
Reply With Quote
 
bowman
Guest
Posts: n/a
 
      07-21-2006
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 =----
 
Reply With Quote
 
JPractitioner
Guest
Posts: n/a
 
      07-21-2006
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 =----


 
Reply With Quote
 
liquid liquid is offline
Junior Member
Join Date: Mar 2007
Posts: 1
 
      03-28-2007
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
java -cp a.jar -jar b.jar => Works on Windows, not on Debian cyberco Java 4 02-14-2006 06:27 AM
jaas.jar, jta.jar jdbc-stdext.jar missing from jdk1.5 RPM muttley Java 0 10-20-2005 02:40 PM
Differences of xercesImpl.jar, xercesImpl-J.jar, dom3-xercesImpl.jar ? Arnold Peters Java 0 01-05-2005 10:59 PM
Differences of xercesImpl.jar, xercesImpl-J.jar, dom3-xercesImpl.jar ? Arnold Peters XML 0 01-05-2005 10:59 PM



Advertisments