views:

647

answers:

3

I've set up a JDBC Realm in my META-INF/Context.xml as shown below, and that works. The trouble is the JDBC driver now have to be placed under $CATALINA_HOME/lib/

Is there any way I can get that realm to load the jdbc driver from elsewhere, such as WEB-INF/lib/ in my webapp ?

META-INF/Context.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context>
  <Realm className="org.apache.catalina.realm.JDBCRealm" 
    driverName="org.postgresql.Driver"
    connectionURL="jdbc:postgresql://daemon/testdb"
    userTable="users" userNameCol="userName" userCredCol="password"
    connectionPassword="xxxxx" 
    connectionName="xxxxx"
    userRoleTable="users" roleNameCol="role"
    digest="MD5"/>
</Context>
A: 

I'm pretty sure you can't do that, no. The Realm exists and is managed outside of the scope of any application. Consider the case where two webapps were deployed, for example, with conflicting drivers.

If you need to keep your JDBC driver inside your WAR, then you'll need to do the security management there also, rather than relying on tomcat to do it for you.

skaffman
A: 

I'm not saying I WOULD do this, but I'm sure you could. Check the catalina.sh (or .bat), in there they set up the classpath, if you add the driver JAR in your webapp to the Tomcat classpath then I don't see why you couldn't use the driver in your Realm. I've never tried this, but I don't see why it would not work.

Gandalf
A: 

Tried this and it doesnt wrk. Tomcat complains of a ClassNotFound for the referenced jar, even though the refereced jar is present under on on the project's WEB_INF/lib folder.

Kavitha