tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <ScottAnd...@BC.com>
Subject RE: Data Sources Overwritten
Date Tue, 19 Jun 2007 16:45:43 GMT
Chris,

Using your method of including the context within the application how do
you adjust for different environments (dev vs production)?  Different
WARs?  

How we do it now is have a context.xml.default included in the
conf/Catalina/NameOfYourHostInServer.xml/ directory where the JNDI
datasource is defined.  That way we can take the exact same WAR that was
deployed on dev and deploy it to production (since they point to
different DBs and thus have different datasources).  

Scott

-----Original Message-----
From: Christopher Schultz [mailto:chris@christopherschultz.net] 
Sent: Tuesday, June 19, 2007 10:35 AM
To: Tomcat Users List
Subject: Re: Data Sources Overwritten

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jeff,
You have not followed my suggestions:

1. Remove all JNDI datasource information from server.xml and never put
it back in.

2. Use a META-INF/context.xml file and bundle it into your WAR file for
deployment. context.xml should include 100% of the JNDI data source
configuration that you need for your app. Consider using <Resource> and
specifying everything instead of trying to use <Resource> /and/
<ResourceParams>.

3. Stop using the Manager to do anything at all.

This will allow your application to setup its own data source instead of
relying on the server to have it ready to go before deployment.
Re-deployments will re-setup the connection, just as it was intended.

This is all documented (poorly, I might add), on this page:
http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.h
tml

Under "MySQL DBCP Example / 2. server.xml configuration", replace the
direction to put the configuration "into server.xml inside your
<Context> element" with "into context.xml inside your <Context>
element".

- -chris

Jeffrey C. Baldwin wrote:
> Also, here is a copy of my server.xml.
> 
> <?xml version='1.0' encoding='utf-8'?>
> <Server>
>   <Listener
className="org.apache.catalina.mbeans.ServerLifecycleListener"/>
>   <Listener
>
className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/
>
>   <GlobalNamingResources>
>     <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"
> maxSpareThreads="75" maxThreads="150"
> minSpareThreads="25">
>     </Connector>
>     <Connector port="8009" protocol="AJP/1.3"
> protocolHandlerClassName="org.apache.jk.server.JkCoyoteHandler"
> redirectPort="8443">
>     </Connector>
>     <Engine defaultHost="localhost" name="Catalina">
> <Host name="localhost" debug="0" appBase="webapps" unpackWARs="true"
> autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
> <Valve className="org.apache.catalina.valves.AccessLogValve"
> directory="logs" prefix="localhost_access_log." suffix=".txt"
> pattern="common" resolveHosts="fal
> se" />
> <Logger className="org.apache.catalina.logger.FileLogger"
> directory="logs" prefix="localhost_log." suffix=".txt"
timestamp="true" />
> <Context debug="0" docBase="mrs2" path="/mrs2" reloadable="true">
> <Logger className="org.apache.catalina.logger.FileLogger"
> prefix="localhost_mrs2_log." suffix=".txt" timestamp="true"/>
>                    <Resource name="jdbc/ZosDataSource"
auth="Container"
> type="javax.sql.DataSource"></Resource>
>                    <ResourceParams name="jdbc/ZosDataSource">
>                        <parameter>
>                            <name>factory</name>
> 
> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
>                        </parameter>
>                        <parameter>
>                            <name>maxActive</name>
>                            <value>5</value>
>                        </parameter>
>                        <parameter>
>                            <name>maxIdle</name>
>                            <value>1</value>
>                        </parameter>
>                        <parameter>
>                            <name>maxWait</name>
>                            <value>10000</value>
>                        </parameter>
>                        <parameter>
>                            <name>username</name>
>                            <value>TS59MRS</value>
>                        </parameter>
>                        <parameter>
>                            <name>password</name>
>                            <value>password</value>
>                        </parameter>
>                        <parameter>
>                            <name>driverClassName</name>
>                            <value>com.ibm.db2.jcc.DB2Driver</value>
>                        </parameter>
>                        <parameter>
>                            <name>url</name>
> 
> <value>jdbc:db2://123.456.789.120:5019/NETSNDB01</value>  <!--
> production 123.456.789.120:5019/NETSNDB01 -->
>                        </parameter>
>                    </ResourceParams>
>                    <Resource name="jdbc/mssql2000ds" auth="Container"
> type="javax.sql.DataSource"></Resource>
>                    <ResourceParams name="jdbc/mssql2000ds">
>                        <parameter>
>                            <name>factory</name>
> 
> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
>                        </parameter>
>                        <parameter>
>                            <name>maxActive</name>
>                            <value>10</value>
>                        </parameter>
>                        <parameter>
>                            <name>maxIdle</name>
>                            <value>1</value>
>                        </parameter>
>                        <parameter>
>                            <name>maxWait</name>
>                            <value>10000</value>
>                        </parameter>
>                        <parameter>
>                            <name>username</name>
>                            <value>rreddy</value>
>                        </parameter>
>                        <parameter>
>                            <name>password</name>
>                            <value>password</value>
>                        </parameter>
>                        <parameter>
>                            <name>driverClassName</name>
>
<value>net.sourceforge.jtds.jdbc.Driver</value>
>                        </parameter>
>                        <parameter>
>                            <name>url</name>
> 
>
<value>jdbc:jtds:sqlserver://123.456.789.96/mrs;user=rreddy;password=pv1
23ankita</value>
>                         </parameter>
>                    </ResourceParams>
>                         </Context>
>                         </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>
> 
> 
> 
> Jeffrey C. Baldwin wrote:
>> Chris,
>>
>> Thank you for the time. However, I'm still not having any luck...
>>
>> Again, I have the entries in server.xml, so if I restart the Tomcat
>> service AFTER deploying the app, all is well.  However, I want the
>> application developers to be able to deploy their app and not have
to,
>> or need to contact me to, restart the Tomcat service.
>>
>> Thanks again!
>>
>> In:
>> /usr/local/tomcat/webapps/mrs2/META-INF
>>
>> I have:
>>
>> <?xml version='1.0' encoding='utf-8'?>
>> <Context docBase="/usr/local/tomcat/webapps/mrs2" path="/mrs2"
>> workDir="work/Catalina/localhost/mrs2">
>>   <Resource auth="Container" description="zos DB2 Connection"
>> name="jdbc/ZosDataSource" type="javax.sql.DataSource"/>
>>   <Resource auth="Container" description="local DB2 Connection"
>> name="jdbc/db2ds" type="javax.sql.DataSource"/>
>>   <Resource auth="Container" description="msql DB Connection"
>> name="jdbc/mssql2000ds" type="javax.sql.DataSource"/>
>>   <ResourceParams name="jdbc/ZosDataSource">
>>     <parameter>
>>       <name>maxWait</name>
>>       <value>10000</value>
>>     </parameter>
>>     <parameter>
>>       <name>maxActive</name>
>>       <value>2</value>
>>     </parameter>
>>     <parameter>
>>       <name>password</name>
>>       <value>test</value>
>>     </parameter>
>>     <parameter>
>>       <name>url</name>
>>       <value>jdbc:db2://123.456.789.120:5019/NETSNDB01</value>
>>     </parameter>
>>     <parameter>
>>       <name>driverClassName</name>
>>       <value>com.ibm.db2.jcc.DB2Driver</value>
>>     </parameter>
>>     <parameter>
>>       <name>maxIdle</name>
>>       <value>1</value>
>>     </parameter>
>>     <parameter>
>>       <name>username</name>
>>       <value>TS59MRS</value>
>>     </parameter>
>>   </ResourceParams>
>>   <ResourceParams name="jdbc/db2ds">
>>     <parameter>
>>       <name>driverClassName</name>
>>       <value></value>
>>     </parameter>
>>   </ResourceParams>
>>   <ResourceParams name="jdbc/mssql2000ds">
>>     <parameter>
>>       <name>maxWait</name>
>>       <value>10000</value>
>>     </parameter>
>>     <parameter>
>>       <name>maxActive</name>
>>       <value>2</value>
>>     </parameter>
>>     <parameter>
>>       <name>password</name>
>>       <value>password</value>
>>     </parameter>
>>     <parameter>
>>       <name>url</name>
>>
<value>jdbc:jtds:sqlserver://123.456.789.96/mrsuat;user=rreddy;password=
password</value>
>>     </parameter>
>>     <parameter>
>>       <name>driverClassName</name>
>>       <value>net.sourceforge.jtds.jdbc.Driver</value>
>>     </parameter>
>>     <parameter>
>>       <name>maxIdle</name>
>>       <value>1</value>
>>     </parameter>
>>     <parameter>
>>       <name>username</name>
>>       <value>rreddy</value>
>>     </parameter>
>>   </ResourceParams>
>> </Context>
>>
>>
>> Christopher Schultz wrote:
>>> Jeffrey,
>>>
>>> Jeffrey C. Baldwin wrote:
>>>> I appreciate all the input guys.  I put everything into server.xml
and
>>>> the application is working great.
>>> You should put that setup into META-INF/context.xml in your webapp
>>> directory (or your WAR file) instead of into server.xml. This is
likely
>>> to fix your problem.
>>>
>>>> So, my question is, I was trying to set it up so that my developers
>>>> could just deploy/undeploy/stop/start their apps all through the
web,
>>>> w/out needing shell access to the server.  Is there a way for them
to
>>>> restart the Tomcat service through a web interface?
>>> Restart the entire Tomcat service? I don't think Tomcat includes
this
>>> capability. You'd have to write your own, separate utility app that
can
>>> take down and restart Tomcat.
>>>
>>>> Is it normal that they should have to restart the entire Tomcat
service
>>>> for their app to be able to talk to the configured database
connections
>>>> in server.xml?
>>> No, it's not. Configuring those connections in context.xml will
>>> certainly alleviate this problem.
>>>
>>> -chris
>>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGeAW+9CaO5/Lv0PARAuPsAJ0YG9txmGYz3GnCLSpdECzWoZNE9wCdGBf8
mISkIX/kQ+mRGOgeYJ1D6Ps=
=BdTV
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message