By default, ColdFusion ships with its own J2EE container (JRun) - so as the project began to take shape, we wanted to be able to create similar JNDI bindings within JRun - so we could closely mimic how the application would behave when deployed on glassfish.
I think I'm being fair saying the documentation for ColdFusion's JRun config files isn't exactly what you'd call the most comprehensive, so here's a rough list of the steps we took to set up JNDI mappings in ColdFusion for a JDBC[JNDI] datasource and for a mail server and what was required to get it all working:
Configuring ColdFusion to work with a JDBC datasource
1. Get the relevant Java JDBC driver for the database you're trying to use (for example, MS SQL Server would use sqljdbc4.jar) and put that jar into your Coldfusion lib folder (e.g. ColdFusion8/lib)
2. In the jrun-web.xml (/Applications/ColdFusion8/wwwroot/WEB-INF/jrun-web.xml), you need to declare the JNDI bindings before you can configure them, so the last few lines of your xml document should look like this:
<resource-ref>
<res-ref-name>jdbc/your-jndi-db-ref-name</res-ref-name>
<jndi-name>your-jndi-db-ref-name</jndi-name>
</resource-ref>
N.B. make sure this is just above the closing tag (</jrun-web-app>)
3. In your jrun-resources.xml (/Applications/ColdFusion8/runtime/servers/coldfusion/SERVER-INF/jrun-resources.xml)
<data-source>
<dbname>name_of_your_database</dbname>
<driver>macromedia.jdbc.sqlserver.SQLServerDriver</driver>
<url>jdbc:macromedia:sqlserver://DB_IP_ADDRESS:PORT;databaseName=name_of_your_database</url>
<username>database_user_name</username>
<password>database_user_password</password>
<encrypted>false</encrypted>
<encryption-class>jrun.security.JRunCrypterForTwofish</encryption-class>
<native-results>true</native-results>
<remove-on-exceptions>true</remove-on-exceptions>
<pool-statements>false</pool-statements>
<initial-connections>1</initial-connections>
<connection-timeout>1200</connection-timeout>
<transaction-timeout>20</transaction-timeout>
<cache-enabled>false</cache-enabled>
<cache-size>5</cache-size>
<cache-refresh-interval>30</cache-refresh-interval>
<jndi-name>your-jndi-db-ref-name</jndi-name>
<poolname>Pool</poolname>
<minimum-size>0</minimum-size>
<maximum-size>2147483647</maximum-size>
<user-timeout>20</user-timeout>
<skimmer-frequency>420</skimmer-frequency>
<shrink-by>5</shrink-by>
<maximum-soft>true</maximum-soft>
<debugging>false</debugging>
<disable-pooling>false</disable-pooling>
<isolation-level>READ_UNCOMMITTED</isolation-level>
<description/>
</data-source>
N.B. This should be just before the closing tag (</jrun-resources>)
An important note here should be that there should be a match between the names in the two files on:
<jndi-name>your-jndi-db-ref-name</jndi-name>
and
<jndi-name>your-jndi-db-ref-name</jndi-name>
respectively.
This should complete the binding for Coldfusion/JRun - restart ColdFusion and you should be good to go.
Configuring ColdFusion to work with a MailServer via JNDI
1. In the jrun-web.xml:
<resource-ref>
<res-ref-name>mail/mailservername-smtp</res-ref-name>
<jndi-name>mailservername-smtp</jndi-name>
</resource-ref>
2. In your jrun-resources.xml:
<mail-session>
<jndi-name>mailservername-smtp</jndi-name>
<description>SMTP Mail Session</description>
<store-protocol>imap</store-protocol>
<transport-protocol>smtp</transport-protocol>
<host>NAME_OF_YOUR_MAILHOST</host>
<user />
<smtp-host>NAME_OF_YOUR_SMTPHOST</smtp-host>
<smtp-user />
<imap-host />
<imap-user />
<pop3-host />
<pop3-user />
<from>postmaster@example.com</from>
<debug>false</debug>
</mail-session>
As before, restart ColdFusion to test whether these changes worked.
Useful References:
http://www.adobe.com/support/jrun/working_jrun/jrun4_jndi_and_j2ee_enc/jrun4_jndi_and_j2ee_enc03.html
http://livedocs.adobe.com/jrun/4/descriptordocs/jrun-resources/jrun-resources.htm