title: Rails 3.1 Deployment to JBoss 4.2.2
body: <p>When deploying a Rails 3.1 app on JRuby to JBoss, I'm having a jndi/jdbc connection issue.  The data source exists and connects fine</p>
  
  <pre><code>17:47:20,862 ERROR [STDERR] JNDI data source unavailable: javax.naming.NameNotFoundException: jdbc not bound; trying straight JDBC
  17:47:20,926 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/MyApp]] unable to create shared application instance
  org.jruby.rack.RackInitializationException: jdbc adapter requires driver class and url
      from C:/opt/jboss/jboss-4.2.2.GA-Virgin/server/default/tmp/deploy/tmp1619261931370223075MyApp-exp.war/WEB-INF/gems/gems/activerecord-jdbc-adapter-1.2.0/lib/arjdbc/jdbc/connection.rb:21:in `configure_connection'
      from C:/opt/jboss/jboss-4.2.2.GA-Virgin/server/default/tmp/deploy/tmp1619261931370223075MyApp-exp.war/WEB-INF/gems/gems/activerecord-jdbc-adapter-1.2.0/lib/arjdbc/jdbc/connection.rb:84:in `initialize'
      from C:/opt/jboss/jboss-4.2.2.GA-Virgin/server/default/tmp/deploy/tmp1619261931370223075MyApp-exp.war/WEB-INF/gems/gems/activerecord-jdbc-adapter-1.2.0/lib/arjdbc/jdbc/adapter.rb:32:in `initialize'
      from C:/opt/jboss/jboss-4.2.2.GA-Virgin/server/default/tmp/deploy/tmp1619261931370223075MyApp-exp.war/WEB-INF/gems/gems/activerecord-jdbc-adapter-1.2.0/lib/arjdbc/jdbc/connection_methods.rb:6:in `jdbc_connection'
      from org/jruby/RubyKernel.java:2097:in `send'
  </code></pre>
  
  <p>...</p>
  
  <pre><code>Caused by: org.jruby.exceptions.RaiseException: (ConnectionNotEstablished) jdbc adapter requires driver class and url
  17:47:23,010 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/MyApp]] Error: application initialization failed
  org.jruby.rack.RackInitializationException: unable to create shared application instance
      at org.jruby.rack.SharedRackApplicationFactory.init(SharedRackApplicationFactory.java:39)
      at org.jruby.rack.RackServletContextListener.contextInitialized(RackServletContextListener.java:45)
      at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3856)
  </code></pre>
  
  <p>Database.yml</p>
  
  <pre><code>###############################################################
  #################### PRODUCTION DATA ##########################
  ###############################################################
  
  production:
    adapter: jdbc
    jndi: java:jdbc/my_datasource
    driver: com.microsoft.sqlserver.jdbc.SQLServerDriver
  </code></pre>
  
  <p>I've checked both the datasource and the Database.yml file but I have no clue why Rails is not finding the datasource.</p>
  
  <p><strong>Update</strong></p>
  
  <pre><code>Warbler config
  
  # Disable Rake-environment-task framework detection by uncommenting/setting to false
  # Warbler.framework_detection = false
  # 
  puts 'Compiling the asset manifests &amp; other files in the pipeline to the disk'
  system('bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile')
  
  # Warbler web application assembly configuration file
  Warbler::Config.new do |config|
  
    # Application directories to be included in the webapp.
    config.dirs = %w(app config lib log vendor tmp)
  
    # Name of the archive (without the extension). Defaults to the basename
    # of the project directory.
    config.jar_name = "MyApp"
  
    # Control the pool of Rails runtimes. Leaving unspecified means
    # the pool will grow as needed to service requests. It is recommended
    # that you fix these values when running a production server!
    config.webxml.jruby.min.runtimes = 1
    config.webxml.jruby.max.runtimes = 1
  
    # JNDI data source name
    # config.webxml.jndi = 'jdbc/rails'
  end
  </code></pre>
  
  <p>Datasource config</p>
  
  <pre><code>&lt;datasources&gt;    
   &lt;xa-datasource&gt;
      &lt;jndi-name&gt;jdbc/my_datasource&lt;/jndi-name&gt;
      &lt;track-connection-by-tx/&gt;
      &lt;isSameRM-override-value&gt;false&lt;/isSameRM-override-value&gt;
      &lt;xa-datasource-class&gt;com.microsoft.sqlserver.jdbc.SQLServerXADataSource&lt;/xa-datasource-class&gt;
      &lt;xa-datasource-property name="ServerName"&gt;myserver&lt;/xa-datasource-property&gt;
      &lt;xa-datasource-property name="DatabaseName"&gt;mydb&lt;/xa-datasource-property&gt;
      &lt;xa-datasource-property name="SelectMethod"&gt;cursor&lt;/xa-datasource-property&gt;
      &lt;valid-connection-sql&gt;SELECT 1&lt;/valid-connection-sql&gt;
      &lt;user-name&gt;user&lt;/user-name&gt;
      &lt;password&gt;pwd&lt;/password&gt;
        &lt;metadata&gt;
           &lt;type-mapping&gt;MS SQLSERVER2000&lt;/type-mapping&gt;
        &lt;/metadata&gt;
    &lt;/xa-datasource&gt;   
  &lt;/datasources&gt;
  </code></pre>