Solved

java application as a service

Posted on 2000-03-19
19
569 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 37

Author Comment

by:meverest
Comment Utility
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
Comment Utility
just realised that 'arguments' field for srvany should be 'AppParameters'

this does not work either.
0
 
LVL 8

Expert Comment

by:diakov
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Promote certifications in your email signature

Has your company recently won an award or achieved a certification? They'll no doubt want to show it off. Email signature images used to promote certifications & awards can instantly establish credibility with a recipient and provide you with numerous benefits.

 
LVL 8

Expert Comment

by:diakov
Comment Utility
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
Comment Utility
when i do this, the dos shell opens, then closes again with no text displayed.

:(

0
 
LVL 37

Author Comment

by:meverest
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
This one solved my problem perfectly!

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

Expert Comment

by:AlexJ030200
Comment Utility
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
Comment Utility
yes!

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

i recommend it highly - thanks again.

cheers.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
nmap scanner? 7 77
DO we need Java installed on a Windows PC and WHY ? 13 77
Droid 4 15 57
ADMT Intra Forest migration questions 7 66
For a variety of reasons, it sometimes makes sense to reboot a Windows-based computer on a regular, perhaps daily basis. This "cures" a lot of ills by resetting processes, flushing caches, refreshing memory, and reestablish network connections. In a…
Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now