This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to start a executable jar as a Windows Service

 
Rakesh Chaudhary
Ranch Hand
Posts: 120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since this has got nothing to do with java i am moving it to General Computing forum.

Did you happen to see this article?

I guess you need to make it an "Automatic" service, for it to start automatically at bootup.
 
Gabriel Vince
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Important: You need a space after each equal sign when using the sc.exe utility program.



good luck
 
Rakesh Chaudhary
Ranch Hand
Posts: 120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi Gab,

Thanks for the response.

I tried your Solution.

The command I passed is



It successfully create's a Service but doesn't start it.

The console pops up a error message

The Service didn't start in a timely fashion.

What do you think might be the mistake.

Thanks
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rakesh Chaudhary wrote:
The console pops up a error message


How about telling us what this error is!

TellTheDetails
 
Gabriel Vince
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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
Posts: 120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 254
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

You may want to try this wrapper. It had worked well for me before.

Cheers,
 
Rakesh Chaudhary
Ranch Hand
Posts: 120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 254
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 254
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[ UD: Please tone down the language. Have you considered what the previous poster said? ]
 
Duc Vo
Ranch Hand
Posts: 254
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..

Thanks to Duc and Gab for their support

Cyaaaaaaa
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
priyas sakorikar,
Your post was moved to a new topic.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic