But eventually I did! Here's how I got both Grails + Tomcat + a JNDI data source working in both the development and production environments...
To set up the JNDI on the development server:
- Add the JNDI configuration to grails.naming.entries to grails-app/conf/Config.groovy in the application
Here's what my configuration looked like (subtitute your own JNDI name, URL, username, password and any other config items you might want):grails.naming.entries = [ "jdbc/myDataSource": [ type: "javax.sql.DataSource", auth: "Container", description: "My data source", driverClassName: "com.mysql.jdbc.Driver", url: "jdbc:mysql://localhost:3306/myschema", username: "myuser", password: "mypassword", maxActive: "100", maxIdle: "30", maxWait: "10000" ] ]
-
Add the MySQL driver JAR (downloadable at mysql.com) to the lib directory in the application
- Configure the application to use JNDI for a development datasource in grails-app/conf/DataSource.groovy
Here's the applicable subset of my DataSource.groovy file:dataSource { pooled = false } // other config stuff environments { development { dataSource { dbCreate = "update" jndiName = "java:comp/env/jdbc/myDataSource" } } // other environments }
To set up the JNDI on the production server:
- Add the JNDI as a Resource in the Tomcat context file (context.xml, or a virtual server-specific context XML)
Here's what my configuration looked like (subtitute your own JNDI name, URL, username, password and any other config items you might want):<Resource name="jdbc/myDataSource" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="myuser" password="mypassword" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/myschema" />
-
Add the MySQL driver JAR (downloadable at mysql.com) to the lib directory in the Tomcat server
- Configure the application to use JNDI for a production datasource in grails-app/conf/DataSource.groovy
Here's the applicable subset of my DataSource.groovy file:dataSource { pooled = false } // other config stuff environments { // other environments production { dataSource { dbCreate = "update" jndiName = "java:comp/env/jdbc/myDataSource" } } }