You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Michael Burbidge <mb...@adobe.com> on 2008/04/29 17:05:24 UTC
Where to define Context element...
I'm trying to define a JNDI resource for a datasource. The Tomcat
documentation lists several different places that you can define a
Context element. I don't want to define it in my app's web.xml and I
don't want to modify tomcat config files. I want to define a companion
file for my app, but I'm having a hard time understanding the
documentation. It says the following, is one place you can define a
Context element:
in individual files (with a ".xml" extension) in the $CATALINA_HOME/
conf/[enginename]/[hostname]/ directory. The name of the file (less
the .xml) extension will be used as the context path. Multi-level
context paths may be defined using #, e.g.context#path.xml.
My web app is in a war called mytest.war, which I deployed to
$CATALINA_HOME/webapps. My web.xml has the following elements:
<servlet>
<servlet-name>mytest</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mytest</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
I placed a file named mytest.xml in $CATALINA_HOME/conf/Catalina/
localhost/mytest.xml. mytest.xml contains the following:
<Context path="/mytest" docBase="mytest"
debug="5" reloadable="true" crossContext="true">
<Resource name="jdbc/mytest" auth="Container"
type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="javauser" password="javadude"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/mytest?
autoReconnect=true"/>
</Context>
My Context defined this way is not loaded. I've checked using the
Tomcat Manager and there is no JNDI resource loaded. What am I doing
wrong?
Thanks,
Michael-
Re: Where to define Context element...
Posted by Michael Burbidge <mb...@adobe.com>.
Chuck,
On Apr 29, 2008, at 8:37 AM, Caldarale, Charles R wrote:
>> From: Michael Burbidge [mailto:mburbidg@adobe.com]
>> Subject: Where to define Context element...
>>
>> The Tomcat documentation lists several different places
>> that you can define a Context element.
>
> Would you like us to guess what Tomcat version you're using, or could
> you take the time to tell us?
Sorry, Tomcat 5.5.26.
>> I don't want to define it in my app's web.xml
>
> That's good, because you can't put a <Context> element in web.xml;
> read
> the documentation again.
Oops, you can make it part of the web application by putting it in /
META-INF/context.xml. That's what I was thinking. Sorry. I was just
thinking I didn't really want it part of my webapp.
>> <Context path="/mytest" docBase="mytest"
>
> Neither the path nor the docBase attributes are allowed here; remove
> them.
>
>> What am I doing wrong?
>
> Look in the logs for anything pertaining to the deployment of this
> webapp.
>
> - Chuck
>
Thanks,
Michael-
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE
> PROPRIETARY
> MATERIAL and is thus for use only by the intended recipient. If you
> received this in error, please contact the sender and delete the e-
> mail
> and its attachments from all computers.
>
> ---------------------------------------------------------------------
> 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
RE: Where to define Context element...
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Michael Burbidge [mailto:mburbidg@adobe.com]
> Subject: Where to define Context element...
>
> The Tomcat documentation lists several different places
> that you can define a Context element.
Would you like us to guess what Tomcat version you're using, or could
you take the time to tell us?
> I don't want to define it in my app's web.xml
That's good, because you can't put a <Context> element in web.xml; read
the documentation again.
> <Context path="/mytest" docBase="mytest"
Neither the path nor the docBase attributes are allowed here; remove
them.
> What am I doing wrong?
Look in the logs for anything pertaining to the deployment of this
webapp.
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.
---------------------------------------------------------------------
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
Re: Where to define Context element...
Posted by David Smith <dn...@cornell.edu>.
> The Tomcat documentation lists several different places that you can
> define a Context element. I don't want to define it in my app's web.xml
Neither should you. Web.xml has its own purpose defined by the servlet spec.
> My web app is in a war called mytest.war, which I deployed to
> $CATALINA_HOME/webapps. My web.xml has the following elements:
You'll have to add a resource-ref block to this. See the tomcat JDBC
howto docs for details. Otherwise it looks good.
> <Context path="/mytest" docBase="mytest"
> debug="5" reloadable="true" crossContext="true">
Drop the path and docBase attributes. They are at best duplicate of
information tomcat can glean from other sources. You can also put this
in a file named context.xml in the META-INF directory of your war file.
> <Resource name="jdbc/mytest" auth="Container"
> type="javax.sql.DataSource"
> maxActive="100" maxIdle="30" maxWait="10000"
> username="javauser" password="javadude"
> driverClassName="com.mysql.jdbc.Driver"
>
> url="jdbc:mysql://localhost:3306/mytest?autoReconnect=true"/>
Drop autoReconnect=true and replace it with a new attribute
validationQuery="select 1" on the Resource element. It'll handle stale
connections much better.
--David
Michael Burbidge wrote:
> I'm trying to define a JNDI resource for a datasource. The Tomcat
> documentation lists several different places that you can define a
> Context element. I don't want to define it in my app's web.xml and I
> don't want to modify tomcat config files. I want to define a companion
> file for my app, but I'm having a hard time understanding the
> documentation. It says the following, is one place you can define a
> Context element:
>
> in individual files (with a ".xml" extension) in the
> $CATALINA_HOME/conf/[enginename]/[hostname]/ directory. The name of
> the file (less the .xml) extension will be used as the context path.
> Multi-level context paths may be defined using #, e.g.context#path.xml.
>
> My web app is in a war called mytest.war, which I deployed to
> $CATALINA_HOME/webapps. My web.xml has the following elements:
>
> <servlet>
> <servlet-name>mytest</servlet-name>
> <servlet-class>
> org.springframework.web.servlet.DispatcherServlet
> </servlet-class>
> <load-on-startup>1</load-on-startup>
> </servlet>
>
> <servlet-mapping>
> <servlet-name>mytest</servlet-name>
> <url-pattern>/*</url-pattern>
> </servlet-mapping>
>
> I placed a file named mytest.xml in
> $CATALINA_HOME/conf/Catalina/localhost/mytest.xml. mytest.xml contains
> the following:
>
> <Context path="/mytest" docBase="mytest"
> debug="5" reloadable="true" crossContext="true">
>
> <Resource name="jdbc/mytest" auth="Container"
> type="javax.sql.DataSource"
> maxActive="100" maxIdle="30" maxWait="10000"
> username="javauser" password="javadude"
> driverClassName="com.mysql.jdbc.Driver"
>
> url="jdbc:mysql://localhost:3306/mytest?autoReconnect=true"/>
>
> </Context>
>
> My Context defined this way is not loaded. I've checked using the
> Tomcat Manager and there is no JNDI resource loaded. What am I doing
> wrong?
>
> Thanks,
> Michael-
>
>
---------------------------------------------------------------------
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