Using the resource as a global resource solves the problem.


-----Original Message-----
From: Derrick Koes 
Sent: Friday, November 05, 2004 7:56 AM
To: '[EMAIL PROTECTED]'
Subject: Tomcat as W2K3 service


Configuration:
W2K3 Server
IIS 6.0
JK2
Tomcat 5.0.24
SQL Server 2000


Starting tomcat (and therefore my web application) as a service produces
an undesireable side effect not seen when starting from command line or
when using the tomcat manager to stop/start my web application.

I have a startup servlet that uses the datasource configured in my
context in its init method.  So, JNDI and therefore my context need to
be available on startup.
JNDI does not appear to be available, or at least my context isn't
available because I can't get my datasource.  Has anyone else seen this
in Tomcat 5.0.x?

Does anyone have a workaround?  My workaround right now is to stop/start
my web application from the tomcat manager
(http://localhost:8080/manager/html).  This isn't the best because when
the machine reboots this step must be done.  I can't rely on the service
starting.

Thanks for the help.

<?xml version='1.0' encoding='utf-8'?>
<Server>
  <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"/>
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>

<!-- Using global resources fixes a bug when tomcat is run as a Windows Service. -->
  <GlobalNamingResources>
    <Environment 
        name="hibernate.dialect" 
        value="net.sf.hibernate.dialect.SQLServerDialect" 
        override="false"
        type="java.lang.String"
        description="Hibernate dialect: net.sf.Hibernate.dialect.[SQLServerDialect|OracleDialect|Oracle9Dialect]"/>
    <Resource name="com/skillsoft/mgs/mail/session" type="javax.mail.Session"/>
    <Resource 
        name="com/skillsoft/ilt/jdbc"
        scope="Shareable" 
        type="javax.sql.DataSource"/>
    <ResourceParams name="com/skillsoft/ilt/jdbc">
      <parameter>
        <name>url</name>
        <value>jdbc:microsoft:sqlserver://localhost:1433;SelectMethod=cursor;sendStringParameterAsUnicode=false;databaseName=MDB</value>
      </parameter>
      <parameter>
        <name>validationQuery</name>
        <value>SELECT iltVersion FROM iltVersion WHERE versionid IN (SELECT param_val FROM master_parameters WHERE param_name=&apos;dbVersion&apos;)</value>
      </parameter>
      <parameter>
        <name>maxIdle</name>
        <value>10</value>
      </parameter>
      <parameter>
        <name>maxActive</name>
        <value>10</value>
      </parameter>
      <parameter>
        <name>driverClassName</name>
        <value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
      </parameter>
      <parameter>
        <name>maxWait</name>
        <value>5000</value>
      </parameter>
      <parameter>
        <name>factory</name>
        <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
      </parameter>
      <parameter>
        <name>username</name>
        <value>sa</value>
      </parameter>
      <parameter>
        <name>password</name>
        <value></value>
      </parameter>
    </ResourceParams>
    <ResourceParams name="com/skillsoft/mgs/mail/session">
      <parameter>
        <name>mail.smtp.host</name>
<!-- This will need to be replaced with a real SMTP server at installation. -->
        <value>@TODO</value>
      </parameter>
      <parameter>
        <name>mail.smtp.port</name>
        <value>25</value>
      </parameter>
      <parameter>
        <name>mail.smtp.sendpartial</name>
        <value>true</value>
      </parameter>
    </ResourceParams>

    <Environment name="simpleValue" type="java.lang.Integer" value="30"/>
    <Resource auth="Container" description="User database that can be updated and saved" name="UserDatabase" type="org.apache.catalina.UserDatabase"/>
    <ResourceParams name="UserDatabase">
      <parameter>
        <name>factory</name>
        <value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>
      </parameter>
      <parameter>
        <name>pathname</name>
        <value>conf/tomcat-users.xml</value>
      </parameter>
    </ResourceParams>
  </GlobalNamingResources>

  <Service name="Catalina">
    <Connector acceptCount="100" connectionTimeout="20000" disableUploadTimeout="true" port="8080" redirectPort="8443">
    </Connector>
    <Connector port="8009" protocol="AJP/1.3" protocolHandlerClassName="org.apache.jk.server.JkCoyoteHandler" disableUploadTimeout="true" redirectPort="8443">
    </Connector>
    <Engine defaultHost="localhost" jvmRoute="tomcat-server:8009" name="Catalina">
      <Host appBase="webapps" name="localhost">
        <Logger className="org.apache.catalina.logger.FileLogger" prefix="localhost_log." suffix=".txt" timestamp="true"/>
        <Valve className="org.apache.catalina.valves.RequestDumperValve" debug="9"/>
      </Host>
      <Logger className="org.apache.catalina.logger.FileLogger" prefix="catalina_log." suffix=".txt" timestamp="true"/>
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"/>
    </Engine>
  </Service>
</Server>
<?xml version='1.0' encoding='utf-8'?>

<Context 
    path="/ilt"
    docBase="P:/ILT"
    workDir="D:/ILTWork"
    crossContext="true" 
    reloadable="true"
    debug="0">
  
<!-- 
The workDir attribute value MUST match the tempDir property
value in the struts-config.xml file or file uploads of over 256K
will not work.
	   
workDir == Pathname to a scratch directory to be provided by this Context
	   for temporary read-write use by servlets within the associated
	   web application. This directory will be made visible to servlets
	   in the web application by a servlet context attribute (of type
	   java.io.File) named javax.servlet.context.tempdir as described
	   in the Servlet Specification. If not specified, a suitable
	   directory underneath $CATALINA_HOME/work will be provided.
-->

<!-- Using global resources fixes a bug when tomcat is run as a Windows Service. -->
  <ResourceLink global="com/skillsoft/ilt/jdbc" name="com/skillsoft/ilt/jdbc" type="javax.sql.DataSource"/>
  <ResourceLink global="com/skillsoft/mgs/mail/session" name="com/skillsoft/mgs/mail/session" type="javax.mail.Session"/>
  
</Context>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to