How to start a executable jar as a Windows Service
Rakesh Chaudhary
Ranch Hand
Joined: Feb 19, 2008
Posts: 118
posted
0
Hi Ranchers,
Does anybody know how to start a executable jar as a Windows Service when system boots.
I have a constraint here of not using any third party tools to do it.
So can somebody highlight some solution towards it.
I tried creating a service using the sc.exe command, its creating a service but I'm not able to start it.I think I am missing some basic thing over here.
Please its urgent.
Thanks in Advance.
Acquire the unexpected.......
Preparing for SCJP 6
I believe you have to provide a way to control the service. I mean from the main() method start a new thread that provides a service and then finish the main(). Then the system (windows) will know that services has started. Still there is problem how to finish it correctly. In Windows API there is a way to provide an interface, java by itself is not built for it.
therefore I suggest you (anyway you said you don't want it) use a tool (e.g. we use javaService) where you can specify input/error file, input parameters, how to start/stop your service, .. and it really works nicely.
Gabriel
Rakesh Chaudhary
Ranch Hand
Joined: Feb 19, 2008
Posts: 118
posted
0
Hi Nitesh,
As I mentioned, the above command create's service.but doen't start it.
i.e if I try to start it from the Command Prompt,after entering the following command I get
after typing NET HELPMSG 2186
I get the following error message
This was all from command prompt
I working on Windows Vista Ultimate
If I try to start the service I created through control panel --> Administrative tools --> Services
I get the following error :
I hope this will help you to help me ?
Thanks
Rakesh Chaudhary
Ranch Hand
Joined: Feb 19, 2008
Posts: 118
posted
0
Hi Gab,
Yesterday I wrote the quote and logged out.Meanwhile I think you were blogging on the same.
Anyways I have mentioned the errors I get,
And yes I will try to find Java Api's which will start/stop the service...
Actually in my Case I want to start a RMI-Server App as a service.On which clients can request certain
tasks...
Thanks
Rakesh!!!
Gabriel Vince
Greenhorn
Joined: Feb 05, 2009
Posts: 24
posted
0
Hi Rakesh,
seems you really miss a controling mechanism.. I wouldn't look for java API, it is native to windows. If you run you java service in unix environment, it works nicely (you just put a shell command into init script). What constraints you to use a third party tool (e.g. JavaService)? Customer/teacher? Why? your proud? Take a note java is built to be OS independed with the cost of OS dependent functionality.. well.. you may code a JNI library, but I don't think it worth the time if there are free tools to help
Best regards
Gabriel
Duc Vo
Ranch Hand
Joined: Nov 20, 2008
Posts: 254
posted
0
Hi,
You may want to try this wrapper. It had worked well for me before.
Cheers,
“Everything should be as simple as it is, but not simpler.” Albert Einstein
Rakesh Chaudhary
Ranch Hand
Joined: Feb 19, 2008
Posts: 118
posted
0
Hey guys,
Thanks for the reply !!!
What constraints you to use a third party tool (e.g. JavaService)? Customer/teacher? Why? your proud?
Gab, my lead has given me the constraint,because I have to create the service and get it running on different machines,so if we are using wrapper than I think we have to copy the wrapper specific files on all of the machines.
Thats what he is not expecting..me to do !!!
Duc I used Java Wrapper for creating the service.It works fine for the first time i.e
If I run the AppName.bat file and than create or rather run InstallAppName.bat.
The service gets created.And runs fine.
After I reboot the system,The service starts but doesn't perform the tasks!!
What I mean by tasks is :
I want the system to start a jar file thats exactly what we do when we run the AppName.bat, right ?
When we start or run AppName.bat, the process javaw.exe starts in the process tree in task Manager,
But after I reboot the service runs but doesn't start the javaw.exe which I think is started by the jar/AppName.bat.
So my doubt is do we have to start the AppName.exe manually everytime,because the wrapper is not doing so!!
Just clear me on this , than I can show it to my leads ,,lets see how they react
Thanks
Duc Vo
Ranch Hand
Joined: Nov 20, 2008
Posts: 254
posted
0
Rakesh Chaudhary wrote:
Duc I used Java Wrapper for creating the service.It works fine for the first time i.e
If I run the AppName.bat file and than create or rather run InstallAppName.bat.
The service gets created.And runs fine.
After I reboot the system,The service starts but doesn't perform the tasks!!
It doesn't seem to be a problem with the service. Your service account presumably has not been changed from the default service account won't be able to open and listen to a network port. You may need to change to another account with higher privilege. It works when you start it because you are an administrator to the system. After restarting the system, the service will run under the service account hence it doesn't perform as expected. Get it fixed, you'll be fine.
Rakesh Chaudhary
Ranch Hand
Joined: Feb 19, 2008
Posts: 118
posted
0
Hey Duc,
Thanks Man !!
But as they say One Problem gives a way to other's
Now when I use my Administrator login the Service starts and the process starts,that mean's the batch file is
starting perfectly.
My Application performs like this :
I give a IP of the system on which the service is running and a request to start some kind of exe on it for
example mspaint or notepad or things like that.
In my case the browser takes the IP and request parameter and doesn't open the console but the exe is started as a process in the processes section of the Task Manager.
I mean to say it starts a process but doesn't launch the notepad window !
I have a feeling that its because of some kind of minor error somewhere.
Thanks
Waiting for your reply
Duc Vo
Ranch Hand
Joined: Nov 20, 2008
Posts: 254
posted
0
Rakesh Chaudhary wrote:Hey Duc,
I give a IP of the system on which the service is running and a request to start some kind of exe on it for
example mspaint or notepad or things like that.
In my case the browser takes the IP and request parameter and doesn't open the console but the exe is started as a process in the processes section of the Task Manager.
I mean to say it starts a process but doesn't launch the notepad window !
I have a feeling that its because of some kind of minor error somewhere.
I don't think you can do it that way. It may only work if the current user is the one who actually started the service. I meant if you log in to the desktop with the service account, then may be you can see the notepad window. It's the window own feature, which I don't know much about. Anyway, the feature that you described doesn't sound like a windows service but like a user feature.
Properly the solution for you is not to install the process as a windows service, but add it to the user loggon script, so that it will start when a user logs on the system.
Hope it help.
Cheers,
Rakesh Chaudhary
Ranch Hand
Joined: Feb 19, 2008
Posts: 118
posted
0
Hi,
Properly the solution for you is not to install the process as a windows service, but add it to the user loggon script, so that it will start when a user logs on the system
Hey its mandatory for me start it as a Service.
I think I am almost their,just missing the last step to get it working.
I changed some config settings in the config file(I am using the Java wrapper )
it was:
wrapper.ntservice.interactive=false
I made it to
wrapper.ntservice.interactive=true
And it started working with a prompt to the user.
About interactive services!!!
Only problem here is I can't stop the process of the exe being started.
Any body here who knows More about Java Wrapper Properties.?
I am using Apache tomcat do I need to paste some files in the Apache settings ?
getting desperate Now!!!
RANCHERS!!!
I get a HUNCH I am near
Rakesh Chaudhary
Ranch Hand
Joined: Feb 19, 2008
Posts: 118
posted
0
[ UD: Please tone down the language. Have you considered what the previous poster said? ]
Duc Vo
Ranch Hand
Joined: Nov 20, 2008
Posts: 254
posted
0
Rakesh Chaudhary wrote:Hi,
Only problem here is I can't stop the process of the exe being started.
What do you want to trigger the stop? To stop just call process.destroy() method (when you run Runtime.exec(), it will return a Process object) or execute a cmd process with taskkill command.
Hope it helps.
@kaveendra: Please don't just copy other's text without any quoting nor putting any of your own text. It's very rude to do so.
Rakesh Chaudhary
Ranch Hand
Joined: Feb 19, 2008
Posts: 118
posted
0
Hi All,
Hey I am finally able to solve my Issue..
With the help of Leif Mortenson from the Java Wrapper Team.
Also thanks to all you guys for your valuable inputs...
But I will try to initiate a another topic on services sometime at next week..