Solved

java application as a service

Posted on 2000-03-19
19
581 Views
Last Modified: 2013-12-28
Status: Waiting for answer.

Points: 350  Date: Friday, March 17 2000 - 12:21PM EST    
Hi Folks,

i have a java application that i currently initiate via a batch file that calls the appropriate class.

is there any way that i can run this java application as a service that can be automatically started on server restart and controlled via the services applet?

thanks and regards.
0
Comment
Question by:meverest
  • 10
  • 6
  • 2
  • +1
19 Comments
 
LVL 8

Expert Comment

by:diakov
ID: 2635025
Hi I have followed the link you posted in the Java forum.
Yes, you have to use SRVANY and INSTSRV excutables from the NT resurce kit.

The first one is a service loader, the second one makes the necessary entry in the registry.

A structured step-by-step solution you can find at:
http://lama.supermedia.pl/docs/NT/srvany.htm

The only remark is that you have to run the main .class file using javaw instead of java, since you do not want aDOS box to appear. Make sure the claspath is set appropriatelly.

Cheers,
  Nik
0
 
LVL 37

Author Comment

by:meverest
ID: 2635047
so you are suggesting that i just run the java class as the srvany 'application' and then enter the java class as argument/s?

i am sure that i tried this already....

i will have another shot to see how it goes.

thanks for your input.
0
 
LVL 8

Expert Comment

by:diakov
ID: 2635197
Yes. I have used it before and it works quite well.

There are detials like the user that runs the service (admin), some adjustments in the registry, etc, but this is quite straightforward.

in general, instsrv will be passed srvany as a parameter.

then srvany registry entry (as far as I recall "Parameters/"Appication") should be adjusted to point to the "javaw myclass.class").
and this is basically it. You can run almost any executable as a service this way. I'm sure there are experts on this forum that will help you with specific stuff if you run into problems.

Cheers,
  Nik
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 37

Author Comment

by:meverest
ID: 2635609
ok,

i have had another shot at this without success.  here is the commandline as run by the batch file:

"d:\jdk1.1.8\Bin\..\bin\java.exe" "-Dinstall.root=d:\MerchantServer" -classpath "d:\MerchantServer\jars\MerchantServer.jar;d:\MerchantServer\jars\iaik_jce_full.jar;d:\MerchantServer\jars\jdk11x_update.jar;.;d:\jdk1.1.8\Bin\..\classes;d:\jdk1.1.8\Bin\..\lib\classes.zip;d:\jdk1.1.8\Bin\..\lib\classes.jar;d:\jdk1.1.8\Bin\..\lib\rt.jar;d:\jdk1.1.8\Bin\..\lib\i18n.jar" au.com.camtech.ec.wrappers.tcpdaemon.TcpDaemon 5000

how ugly is that!?

ok, so i have put "d:\jdk1.1.8\Bin\..\bin\java.exe"  as the 'application value, and put "-Dinstall.root=d:\MerchantServer" -classpath "d:\MerchantServer\jars\MerchantServer.jar;d:\MerchantServer\jars\iaik_jce_full.jar;d:\MerchantServer\jars\jdk11x_update.jar;.;d:\jdk1.1.8\Bin\..\classes;d:\jdk1.1.8\Bin\..\lib\classes.zip;d:\jdk1.1.8\Bin\..\lib\classes.jar;d:\jdk1.1.8\Bin\..\lib\rt.jar;d:\jdk1.1.8\Bin\..\lib\i18n.jar" au.com.camtech.ec.wrappers.tcpdaemon.TcpDaemon 5000
 as 'arguments' value.

does this look right?

regards.


0
 
LVL 37

Author Comment

by:meverest
ID: 2635630
just realised that 'arguments' field for srvany should be 'AppParameters'

this does not work either.
0
 
LVL 8

Expert Comment

by:diakov
ID: 2635670
Please, pay attention to my comments. In the link I provided steps 6,7,8 tell you the names of the entries.
The cmd line string should be then something like:
"d:\jdk1.1.8\Bin\..\bin\javaw.exe -Dinstall.root=d:\MerchantServer  -classpath d:\MerchantServer\jars\MerchantServer.jar;d:\MerchantServer\jars\iaik_jce_full.jar;d:\MerchantServer\jars\jdk11x_update.jar;.;d:\jdk1.1.8\Bin\..\classes;d:\jdk1.1.8\Bin\..\lib\classes.zip;d:\jdk1.1.8\Bin\..\lib\classes.jar;d:\jdk1.1.8\Bin\..\lib\rt.jar;d:\jdk1.1.8\Bin\..\lib\i18n.jar au.com.camtech.ec.wrappers.tcpdaemon.TcpDaemon 5000"

Note that I use javaw.exe, not java.exe

Also, the classpath can be put in the environment before hand.

Keep me posted if you have problems.

Cheers,
  Nik
0
 
LVL 37

Author Comment

by:meverest
ID: 2635707
thanks again diakov, but if i do it all in the 'Application' entry as suggested, i get an error 2140: An internal Windows NT error occured on starting the service.

and i have tried many combinations with java or javaw - these don't seem to make a difference (as in neither works)

by the way, this application is supposed to run a tcp server on port 5000 and this is how i can tell that it is not running (ie 'telnet' to port 5000 fails)

regards.
0
 
LVL 8

Expert Comment

by:diakov
ID: 2635894
I have tried a simple application in java, it worked from the first try.

I did the following:

started the instsrv with:
instsrv test_java C:\freelance\test_java_as_service\srvany.exe

to create a service test_java

then with regedit I created a key Parameters in the test_jav service entry.
In this key I created 3 string values:
Application = "c:\jdk_path\bin\javaw.exe"
AppParameters = "-cp %classpath%;./ ViewData"
AppDirectory = "C:\freelance\test_java_as_service"

The from the control pannel I started the services applet, checked the "Allow service to interact with desktop" chekbox, because my application opens a GUI window and started the service manually.

It worked.

Now in your case, you have to choose appropriate startup directory in AppDirectory, enter the path + name of the javaw executable in the Application and paste all parameters in the AppParameters value.

Cheers,
  Nik
0
 
LVL 37

Author Comment

by:meverest
ID: 2637578
i am rejecting this answer for two reasons:

1.  i still can't get this to work with my particular java app,
2.  i want this question to remain visible in the top 10 questions.

thanks so much for your help so far diakov, but there must be something unusual about this particular class that does not allow it to run this way.

simple diagnosis suggests that finding required classes is failing.

i am particularly suspicious of the "-Dinstall.root=d:\MerchantServer" term, as when i enter just java.exe by itself, i do noit see any reference to '-Dinstall.root'

unfortunately i am not familiar enough with java calling requirements to figure that out...

regards.
0
 
LVL 8

Expert Comment

by:diakov
ID: 2638067
I understand, try this:

-D set a system property "install.root" during loading of the application.
To see what the problem is, enable the "interacting with desktop" for this service (from control panel, sevices, start up), and use java.exe (not javaw.exe) to run in a DOS box. There you will be able to see the Java error messages, that lead to the service error. Then report back here.

Cheers,
  Nik
0
 
LVL 37

Author Comment

by:meverest
ID: 2638145
when i do this, the dos shell opens, then closes again with no text displayed.

:(

0
 
LVL 37

Author Comment

by:meverest
ID: 2638251
actually, as it turns out, the dos shell opens with a lot of output, then immediately closes within a split second.  i have tried to capture this output with prtsc, but i have not been able to do better than just before the text is displayed, or just after the box closes :(

some ideas of how to capture that output might prove useful.
0
 
LVL 8

Expert Comment

by:diakov
ID: 2638750
Hm, that is strange. When I try my example service I start/stop it as a manual service - the dos box stays open. Do you use start/stop?

I'll thinkabout how this can be done.

An idea would be to write all this into a bat file and use not java.exe but cmd.exe as the srvany Application with AppParameters the .bat file. May be the dos box will stay open.

Try it out and tell me.

Meanwhile, JObject API might work for you :-)

Cheers,
  Nik
0
 
LVL 37

Author Comment

by:meverest
ID: 2638805
thanks,  i will.

> Meanwhile, JObject API might work for you :-)

it might, if i could figure out how to use it! ;-)

cheers.

0
 
LVL 19

Expert Comment

by:Jim Cakalic
ID: 2640899
G'day.

Using the JObject API is intrusive -- you have to alter the implementation of your application so that it registers itself as a listener for service control events and provide methods that allow some class in your application (which implements the ServiceControlListener interface) to catch the four NT service control events (stop, pause, continue, shutdown). If everything I just said sounds like so much gibberish, then forget it. Also, if you can't or don't want to change the application in any way, then forget it. Otherwise, you would have to have a development environment installed -- although I wouldn't particularly recommend MS VJ++. It appears from your classpath settings in previous posts that you already have jdk1.1.8 installed so you should be able to run C:\jdk1.1.8\bin\javac to compile.

Under which account are you trying to run this service? Is it the same one you normally use to logon to the system and run the application from a batch file? If "System Account" is checked in the "Log On As" option of the Services Startup... dialog, the environment running as a service may be (substantially) different than the environment when you run the batch file. PATH and CLASSPATH are just two of the environment variables which could be different. I notice that "." is one of the path components in your classpath. Is there any reliance on the current working directory? If so, this could be part of the problem.

Jim
0
 
LVL 2

Accepted Solution

by:
AlexJ030200 earned 350 total points
ID: 2651103
I've found these three resources in jars.com. Hope they can help to solve your problem.

------------------

ServiceInstaller (BG2-22) ServiceInstaller (formerly KCMDG ServiceMaster) is a utility that lets you easily install a pure Java application (or any appropriate executable) as an NT Service.  Safely create (or remove) an NT Service with dependencies and runtime arguments without manually editing the registry. Written in C++, the utility will install Java apps running Java 1.02 thru 1.2. No special coding is necessary in the Java app, ServiceMaster handles all of the NT specific details.

 Submitted by :        Bill Giel, bgiel@ct2.nai.net
 Resource URL :        http://www.kcmultimedia.com/smaster
 Source Code :         Not Available
 Detailed Review :     Not Available
 Type :                Application
 Category :            Utilities - Other
 Language :            Other
 Marketing :           Freeware - Release
 Version :             1.0
 Date Submitted :       Mon Nov 23 20:41:01 1998

TFTP Server for Java (FC4-46) IBM TFTP Server (TftpSvr) implements the Trivial File Transfer Protocol (TFTP) as a server process. It allows TFTP clients running on any host to read and write files to the server. On Windows/NT, TftpSvr installs as an NT Service, which means that it runs in the background whether or not a user is logged onto the workstation.
  Submitted by :       Frank Carlos, solrac@us.ibm.com
 Resource URL :        http://www.alphaworks.ibm.com/formula/tftp
 Source Code :         http://www.alphaworks.ibm.com/formula/tftp
 Detailed Review :     Not Available
 Category :            Business - Other
 Language :            Java
 Marketing :           Freeware - Release
 Version :             1.0
 Date Submitted :      Mon Oct 12 15:10:40 1998

Running Pure Java as an NT Service (BG2-24) This is a tutorial for creating an executable launcher for a pure java application that permits installing/removing the app as an NT service. Included are downloadable Win32 and Java source and binaries for an example, with emphasis on Java 2 apps.  Unlike other solutions, this technique is not dependent on the MS Java SDK, and requires no special modification of the actual Java application.
  Submitted by :         Bill Giel, bgiel@ct2.nai.net
 Resource URL :          http://www.kcmultimedia.com/javaserv
 Source Code :           http://www.kcmultimedia.com/javaserv
 Category :              Programming - Other
 Language :              Java
 Marketing :             Freeware - Release
 Date Submitted :        Sun May 16 19:57:39 1999
0
 
LVL 37

Author Comment

by:meverest
ID: 2651705
This one solved my problem perfectly!

 Resource URL :        http://www.kcmultimedia.com/smaster
 
many thanks.
0
 
LVL 2

Expert Comment

by:AlexJ030200
ID: 2652017
I'm glad it's done. Last year when I had the same problem that one was not listed and I used the third one which is only a document.

See you.
0
 
LVL 37

Author Comment

by:meverest
ID: 2652063
yes!

and it is most excellent - quick easy and no drama ;-)

i recommend it highly - thanks again.

cheers.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to resolve user quota error? 13 71
form builder not starting 3 39
windows 10 versions 3 36
see android hidden files 10 32
Our Group Policy work started with Small Business Server in 2000. Microsoft gave us an excellent OU and GPO model in subsequent SBS editions that utilized WMI filters, OU linking, and VBS scripts. These are some of experiences plus our spending a lo…
If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question