• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Tomcat as a service

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can I use tomcat as a service on windows 2000?
Also, is Apache a better option than tomcat?
- Ria
 
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In <tomcat_home>/bin is a program called 'tomcat.exe' it can be used to make a service in windows NT/2000/XP.
Here is the way I have done it:

PS. The last call to 'tomcat' should be in one line!
/Rene
[ July 10, 2002: Message edited by: Rene Larsen ]
 
Ranch Hand
Posts: 250
Python Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While searching for the solution to start Tomcat as a Window service I came across this post. But how do I us ethis script. Will the ranchers help me please.
 
Rene Larsen
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You just need to put the shown lines in af cmd-script - e.g. 'installTomcatService.cmd' - doubleclick on 'installTomcatService' and the service should be installed.
Remember to set 'CATALINA_HOME', 'JAVA_HOME' and the path to '<tomcat_install>/bin' before install.
Rene
[ March 08, 2003: Message edited by: Rene Larsen ]
 
Debashish Chakrabarty
Ranch Hand
Posts: 250
Python Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For this problem, I tried using a third party solution (JavaService) which is here and it worked perfectly.
I was interested in Rene's solution since it does not involve any other application. However using the above-suggested solution gives me the following error at command line (My tomcat is at C:\netbeans\tomcat404 and jdk is at c:\jdk1.3). My command file was kept in the Bin folder of tomcat.
The command file code is as follows (sorry I hardcoded many things):

The result of running this is as follows. The main problem seems regarding the additional parameter we supply. Many are not recognized by tomcat.exe (BTW tomcat.exe is 64kb file in my tomcat),

Help please
Regards,
Debashish
[ March 08, 2003: Message edited by: Debashish Chakrabarty ]
 
Rene Larsen
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

should be called in one line..
you should also use the 'server' in this call: 'C:\jdk1.3\jre\bin\hotspot\jvm.dll' like this: 'C:\jdk1.3\jre\bin\server\jvm.dll'
Rene
[ March 08, 2003: Message edited by: Rene Larsen ]
 
Rene Larsen
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
BW: the other service you have found is the same as 'tomcat.exe' just rename it :-)
Rene
 
Debashish Chakrabarty
Ranch Hand
Posts: 250
Python Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Rene it worked.
There are a few questions in my mind however. I presume that tomcat.exe (resides in the bin directory of tomcat installation) is shipped along with tomcat. Right? I looked at the properties of the executable and found that it infact belongs to "Alexandria" the same company that is also selling it as a third party solution called "Java Service". My questions why should they do that if their application is already shipped as part of Tomcat? I was concerned about this because (though their solution is free) I must also distribute their license when using "Java Service" which is not the case if I utilize the solution suggested by Rene.
Few other questions:
(1) Will this solutions work similarly with jdk1.4?
(2) Are you aware of any known problmes of using Tomcat with jdk1.4?
Thanks for your time and advice Rene.
Regards,
[ March 09, 2003: Message edited by: Debashish Chakrabarty ]
 
Debashish Chakrabarty
Ranch Hand
Posts: 250
Python Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rene for your post. I have now succeeded in intalling the service using my product installer. However a new problem has now surfaced. If I try to mnually start the service using the "start" link in "Services" the progress-bar shows up starting the service but then it also stops immediately saying--"The service on Local computer started and then stopped. Some services stop automatically is they have no work to do, for example the Performance log and alert service".
Interestingly, I remember having started the service yesterday manually and it did successfully. The same problem persist even if I install the service directly (instead of doing that thru my product installer).
Can you help me out?
 
Rene Larsen
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What have you changed since yesterday?
Have you install java 1.4.x?
Maybe the JAVA_HOME isn't set correct.
Rene
 
Debashish Chakrabarty
Ranch Hand
Posts: 250
Python Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rene,
This is what I figured out.
Actually I had two versions of Tomcat on my machine. One was Tomcat4.0.4 which came along with my Netbeans IDE and another which we ship with our product i.e.Tomcat 4.0.3. I tried all the combinations and found out that though the service is installed successfully with both Tomcat versions, it automatically stops the service (whether you try to start the service manualy or restart yr machine for the service to start automatically). This was mentioned in my previous post. In short the service worked well only with Tomcat4.0.4 and *not* with ver4.0.3.
Also, the call to the JVM.dll should be either 'C:\jdk1.3\jre\bin\hotspot\jvm.dll' or 'C:\jdk1.3\jre\bin\classic\jvm.dll'. If we use 'C:\jdk1.3\jre\bin\server\jvm.dll' the abovesaid problem occurs, i.e. the service won't start.
I wonder what would happen if I try it using jdk1.4 and Tomcat4.1.x which I intend to use eventually with my product.
Now I have these doubts:
(1) What does -xrs mean in the tomcat.exe call? What if I remove it?
(2) The service that we install will let Tomcat run at the default port of 8080. What if I wish to run it at some other port say 4160?
Thanks
[ March 11, 2003: Message edited by: Debashish Chakrabarty ]
 
Rene Larsen
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the error in the 'Event Viewer' under 'Application'?
Have you tried to reinstall the service when you changed tomcat version?
Rene
 
Debashish Chakrabarty
Ranch Hand
Posts: 250
Python Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was experimenting a bit regarding compatibility of Tomcat with jdk1.3 and jdk1.4 and trying Tomcat as NT service.
The batch file mentioned above is suitable to install Tomcat as a service but the service would run only when the paths for jvm.dll and catalina home do not contain any spaces. If they do (say your Tomcat or jdk are under Program Files) the registry entries become all wrong instead of just two entries for jvm & tomcat path there will be many entries as the path mentined by you will break the string on spaces. You can verify this by going to registry.
I am not able to find any remedy for this. I was desperate to use Tomcat as a service with my application which would always be installed under Program Files and the application directory name also contains spaces. It seems installing the service through this batch file would not be possible in my case then
Secondly, in jdk1.4 the locations of jvm.dll are no more in JAVA_HOME/jre/bin/hotspot or classic directories but in JAVA_HOME/jre/bin/server and client directories. So specifying the jvm path in the batch file is important considering the jdk version you are using.
 
Debashish Chakrabarty
Ranch Hand
Posts: 250
Python Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I continuation with my quest on this topic I recently encountered another problem.
When I am running tomcat4.1.18 as a service (with jdk1.3) my application is not able to read some property and xml files that exist in my application's bin directory while it is able to read the web.xml files kep in apllication's web-inf. My application directory structure is exactly the same as Tomcat's except for the fact that I removed the docs and examples and put my application files in the webapps folder. Also few of my xml and property files are kept in bin folder.
The problem occurs because as a service Tomcat considers the working directory as c:\windows\system32 (on my XP machine).
My questions are:
(1) Why is this happening? (the application works fine if I start Tomcat using startup.bat i.e. do not run it as a service)
(2) While installing tomcat as a service we specify the JVM.dll path as well catalina-home as paramters to tomcat.exe.
Is there any way we can specify the working directory to the service as well? (since I want my working directory to be my application's bin directory instead of system32).
Any help will be greatly appreciated.
Thanks..
[ March 17, 2003: Message edited by: Debashish Chakrabarty ]
 
Debashish Chakrabarty
Ranch Hand
Posts: 250
Python Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok..Ok..guys I seem to have figured it out. Nothing clever..we can specify the "working directory" to tomcat.exe using the parameter -current. My advise would be to read about all the parameters tomcat.exe takes by typing tomcat.exe ?.
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As for the remedy for LFN's ("Program Files") and spaces... just use the 8.3 version of that directory. "Progra~1" for "Program Files".
 
Debashish Chakrabarty
Ranch Hand
Posts: 250
Python Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are right Mike. I tried using DOS names once. But now that I am running my Tomcat as service and my application which uses tomcat is installed in Program Files I can safely say that the trick is in "passing" the parameters to tomcat.exe while installing the service.
Earlier I used variables in my batch file for JVM path etc and if they contained spaces, things would go wrong since the registry entries would treat spaces as separating different entries. Then I decided to remove all those variables alltogether and pass the parameters in quotes. For eg.in my VISE installer I write the following to my batch file:
This whole thing should come in one line (had too much trouble initially with this) It works smooth

-edited by Mike C to break the one line into several (otherwise this page blows up)
[ March 19, 2003: Message edited by: Mike Curwen ]
[ March 19, 2003: Message edited by: Debashish Chakrabarty ]
 
Greenhorn
Posts: 10
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In newer e.g. Tomcat 5.5 version and Windows (e.g. Server 2008) there is a service.bat file that is used to install (or remove) the Tomcat service.
Can add a --StartPath parameter there to set the working directory. This is very useful when Tomcat is running on a drive other than where Windows is installed and you don't want to have to specify specific drive letters for file paths as it will use the drive that the start path is on.

rem Set extra parameters
REM Added --StartPath=%CATALINA_HOME%\bin
REM - Without this the working directory would be C:\Windows\System32
REM which would cause trouble if Tomcat were located on another drive
REM because attachments location is intentionally non-specific about drive
REM in order to be able to use same execution.properties everywhere.

"%EXECUTABLE%" //US//%SERVICE_NAME% --JvmOptions "-Dcatalina.base=%CATALINA_BASE%;-Dcatalina.home=%CATALINA_HOME%;-Djava.endorsed.dirs=%CATALINA_HOME%\common\endorsed" --StartMode jvm --StopMode jvm --StartPath=%CATALINA_HOME%\bin

 
To do a great right, do a little wrong - shakepeare. twisted little ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic