| |
OC4J as a Windows Service
From time to time, questions appear on OTN
about running OC4J as a Windows service.
When you are using the
OracleAS installation, you really don't need this since we provide a
very good process management and monitoring service called OPMN. This
is responsible in the OracleAS environment for starting a defined set
of processes, monitoring them as they are running, notifying other
components about their availability, and restarting them as necessary
should they fail for any reason. OPMN itself is rooted as a Windows
service, so it can be started automatically by Windows, and then
perform it's own operations to manage the OracleAS processes.
With OC4J standalone, you don't get the benefits of OPMN, so perhaps you may
have a need to configure OC4J as a Windows service to have it
automatically start whenever Windows is booted.
A google search revealed quite a few different service wrappers to
allow Java programs to be registered and run as Windows services.
One that sounded interesting to me (open source and free) is called JavaService -- http://www.alexandriasc.com/software/JavaService. It looks like it hasn't been updated for quite a while, but it seemed to work OK on my W2K laptop.
The JavaService distribution ships with a set of example batch scripts which create a Windows service for Tomcat.
I altered one of the examples to work with OC4J 904 and tested it out.
It seems to work fine -- it starts correctly, services requests, and
terminates when requested. Most importantly, uninstalling the service
worked as well.
My modified installation script is shown below -- it should go into the JavaService/bin directory.
You run it as follows
>installOC4J904.bat <path-to-jdk> <path-to-oc4j> (client | server)
So if the JDK was installed in d:javajdk142 and OC4J was installed as d:javaoc4j-904 then you'd run it as
>installOC4J904.bat d:\java\jdk142 d:\java\oc4j-904 server
This will create a new Windows service called OC4J904 which you can
manage via as a normal Windows Service. It puts a copy of the actual
JavaSerice executable into the j2eehome directory of the specified OC4J installation.
If you wish to to remove the service, cd to OC4J_HOME\j2ee\home and execute
>OC4J904.exe -uninstall OC4J904.
The OC4J904 service is configured to send its logging outputs to OC4J_HOME\j2ee\home\log\oc4j904-stderr.out and oc4j904-stdout.out. Check these once you start the service to make sure it started correctly.
installOC4J904.bat
---------------------------
@echo off
echo --------
echo Usage: %0 <JDK_HOME> <OC4J-HOME> (client/server)
echo NOTE: You MAY NOT use spaces in the path names. If you know how
echo to fix this, please tell me.
echo Example: %0 d:\java\jdk142 d:\java\oc4j-904 server
echo --------
if "%1" == "" goto eof
if "%2" == "" goto eof
if "%3" == "" goto eof
set J2EE_HOME=%2\j2ee\home
copy JavaService.exe %J2EE_HOME%\OC4J904.exe > nul
%J2EE_HOME%\OC4J904.exe
-install OC4J904 %1\jrebin\%3\jvm.dll
-Djava.class.path=%J2EE_HOME%\oc4j.jar -start
com.evermind.server.OC4JServer -params -config
%J2EE_HOME%\config\server.xml -out %J2EE_HOME%\log\oc4j904-stdout.log
-err %J2EE_HOME%\log\oc4j904-stderr.log
goto eof
:eof
Note that we are actually invoking the direct class
which starts the OC4J container. This is a private API, so there's no
guarantee that this will remain consistent from release to
release.
Since the service is not started from the OC4J_HOME/j2ee/home
directory, OC4J needs to be told where to locate the root configuration
file to use. My script assumes that the default configuration file
(server.xml) is to be used.
© Copyright 2004 buttso.
Last update: 4/28/2004; 1:28:30 PM.
|
|