Mar 22
It is always frustrating if you have to munge a server.xml
in Tomcat, or the equivilent in other servers. At that point, your nice deployable .war file requires a README that says “oh, and make sure your server.xml is setup like this…”.
At least now we have a feature that lets us put context information in the war file. I didn’t know that Tomcat supported this until recently:
<?xml version="1.0" encoding="UTF-8"?> <Context> <Resource auth="Container" description="DB Connection" name="jdbc/ebackbay" type="javax.sql.DataSource" password="" driverClassName="com.mysql.jdbc.Driver" maxIdle="2" maxWait="5000" validationQuery="select * from testdata;" username="root" url="jdbc:mysql://localhost/ebackbay" maxActive="4"/> <WatchedResource>WEB-INF/web.xml</WatchedResource> <WatchedResource>META-INF/context.xml</WatchedResource> </Context>
March 22nd, 2005 at 5:29 pm
This works great on Tomcat 5, but if it you want it to work on Tomcat 4 – you have to use the Manager app to deploy your WAR.
March 23rd, 2005 at 1:15 am
I am using this since Tomcat5 is out and its really nice. I wish there would be some kind of standard so that this also works in resin or jetty.
March 23rd, 2005 at 9:50 am
For the sake of modularity, I try to avoid ever putting anything into the server config related to the application. It just causes to many problems if you have to move apps between servers. It’s much much easier to make the .war file a standalone deployable unit.
FYI, we typically use Resin. And using a application framework like Spring can put app details, like DB connection info into the app (where I think they belong).
March 24th, 2005 at 3:43 am
Nice feature. I wasnt aware of it. However after some thought I think I would rather start using the jmx beans to deploy / undeploy applications. Atleast that way I preserve the cros deployment features of a war. Yes it definitely has an extra overhead to know of the beans which do the actual stuff.
anand
March 31st, 2005 at 7:47 pm
Patrick, you say that the db connection info belongs in the app? What happens when the database is moved to a different server? Just curious.
April 12th, 2005 at 11:10 am
Hi
I could not configure Webapplication on my Tomcat 5.5.7 so that it worked with the context.xml in the META-INF folder. I always get the exception:
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class ” for connect URL ‘null’
my context.xml looks like this:
WEB-INF/web.xml
META-INF/context.xml
and my server.xml like this:
WEB-INF/web.xml
META-INF/context.xml
can someone maybe help me? I would like to use this feature!
Ohh and with the content of the context.xml in the server.xml everything worked fine!
thx,
Christian
May 5th, 2005 at 8:46 pm
Christian, I am having the same issue.
Also, your xml posting appears blank.
Has anyone found a solution to this problem yet?
May 19th, 2005 at 4:46 pm
Does the context.xml you show work as-is, Dion? When I try this with Tomcat 5.0.28 with a similarly-configured context.xml, tomcat throws an exception at startup claiming I need to specify a context path. Do you have a different experience? If so, with which version of tomcat?
November 26th, 2005 at 10:56 pm
Hi, I also have the error
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class ” for connect URL ‘null’
March 28th, 2006 at 11:33 pm
Note that the META-INF/context.xml trick only works if you are creating a WAR file. If you are deploying by pointing Tomcat to an expanded directory structure, this trick won’t work. I am using Tomcat 5.0.
July 15th, 2006 at 3:07 pm
Christian, Scott, Vivian
you would get this error, if you try to use a 5.0 style jndi datasource definition in tomcat 5.5 or vice versa. maybe this is the cause for your problems?
February 12th, 2009 at 10:37 am
On your web.xml add the following elements
Database Connection
jdbc/ebackbay
javax.sql.DataSource
Container
Shareable
February 12th, 2009 at 10:38 am
That didn’t work
There are xml elements to add on your application’s web.xml
view this page: http://www.oreillynet.com/cs/user/view/cs_msg/7193
hope this helps.
February 25th, 2009 at 1:24 am
hi Christian Menkens,
Same problem came for me also
Solution:
i think , your are not included the mysql driver jar file inside your /WEB-INF/lib directory.
Check the mysql driver jar is placed in /WEB-INF/lib directory. if not include the
jar then restart the tomcat.
for me it works fine ..
August 5th, 2009 at 3:16 am
@Adam (comment 10)
The META-INF/context.xml “trick” works fine for war files and expanded directorie structures. It is not as trick. It is a normal configuration alternative.
I am using Tomcat-6.0.18.
November 17th, 2009 at 5:21 am
Thanks Adam Buckley .. ur idea was helpful.
December 12th, 2009 at 12:54 pm
Hi Dion Or any one Please help me.
I am using tomcat version 5.0.27 and trying to deploy my war file with the context information , But having trouble . War file is expanding properly but it is creating kd.xml FOLDER under C:\tomcat\Tomcat 5.0\conf\Catalina\localhost ( where kd is my war file name) , not sure why it is creating Folder with that name under conf\Catalina\localhost . The end result is exception in the log says “java.io.IOException: java.io.FileNotFoundException: C:\tomcat\Tomcat 5.0\conf\Catalina\localhost\kd.xml (Access is denied)”
My context.xml file below
WEB-INF/web.xml
META-INF/context.xml
username
root
password
driverClassName
com.mysql.jdbc.Driver
url
jdbc:mysql://localhost:3306/test
Thanks for your help
December 12th, 2009 at 1:52 pm
Sorry guys , This was a bug in tomcat 5.0.27 . I did apply the fix and the issues was resolved
https://issues.apache.org/bugzilla/show_bug.cgi?id=29688
But now I am getting into another issue
Cannot create JDBC driver of class ” for connect URL ‘null’
I copied the required jar to Lib folder , But still getting this error , Can you please help me . am I missing any thing?
Regards
December 14th, 2009 at 8:43 am
Hi Dion ,
I am able to resolve this issue finally , problem is with context path.
Regards
February 4th, 2010 at 9:17 am
I’m using Tomcat 6 and it works. I added the JDBC details to a copy of the default context.xml and put it in the applications META-INF folder. *** Note. you must put it in the WAR file editing the expanded folder does not work ***
February 10th, 2010 at 10:21 am
Does anyone know how to keep the context.xml file from being overwritten each time a new WAR file is deployed? Here’s the situation: our context.xml file contained in the WAR file is meant to be configured AFTER it is deployed. For example, our client services team will fill in values like database connection strings and such. However, when the WAR file is redeployed these values are overwritten, and they will have to fill in those values again. I’d like to know if anyone has a solution to this.
Thanks!