07/01/15

Grails web app deployment on Tomcat 6

I have a simple grails/groovy application which correctly runs on development mode, but I wasn't able to deploy it directly on our Tomcat6 server.

Two errors haunted my objective, but before discovering it I needed a better log.

Grails app logging with Tomcat

I modified grails-app/conf/Config.groovy partially following what suggested on this post:

// MOD for writing in logs of the Tomcat server
def catalinaBase = System.properties.getProperty('catalina.base')
if (!catalinaBase) catalinaBase = '.'   // just in case
def logDirectory = "${catalinaBase}/logs"
def appName = "jethosweb"

// log4j configuration
log4j.main = {  
    appenders {
       rollingFile name:'stdout', file:"${logDirectory}/${appName}.log".toString(),  maxFileSize:'100MB'
       rollingFile name:'stacktrace', file:"${logDirectory}/${appName}_stack.log".toString(), maxFileSize:'100MB'
    }

    error  'org.codehaus.groovy.grails.web.servlet',        // controllers
           'org.codehaus.groovy.grails.web.pages',          // GSP
           'org.codehaus.groovy.grails.web.sitemesh',       // layouts
           'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
           'org.codehaus.groovy.grails.web.mapping',        // URL mapping
           'org.codehaus.groovy.grails.commons',            // core / classloading
           'org.codehaus.groovy.grails.plugins',            // plugins
           'org.codehaus.groovy.grails.orm.hibernate',      // hibernate integration
           'org.springframework',
           'org.hibernate',
           'net.sf.ehcache.hibernate'
}

 

File permissions

The logs weren't helping me to scope the problem. 
ERROR StackTrace  - Full Stack Trace:
org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'transactionManagerPostProcessor' 
The first problem (holding also on Tomcat 7) is due to file permissions. By default the standard production db tries to write in the /var/lib/tomcat7/web-app/.. directory.

I modified the configuration in grails-app/conf/DataSource.groovy to put the database file in a tmp directory. (I've found a suggestion toward the solution here.) Note: my application does not need a real persistent database. If it is not your case, use another directory or you risk to lose the db at a certain moment.

    production {
        dataSource {
            dbCreate = "update"
            url = "jdbc:h2:file:/tmp/my app-grailsdb;MVCC=TRUE" 

    [..]

 

Tomcat6 compliance

The app runs on Tomcat7, but not on Tomcat6. This second problem was also difficult to scope through the logs,
ERROR context.ContextLoader  - Context
initialization failed
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'grailsApplication' defined in ServletContext
resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed;
nested exception is java.lang.NoClassDefFoundError: javax/servlet/AsyncContext 
I modified grails-app/conf/BuildConfig.groovy to account compliance with Tomcat (a fast search on stackoverflow helped with this.)

grails.servlet.version = "2.5" // for TOMCAT 6

After that, I rebuilt the app

> grails clean
> grails clean-all
> grails war
 
and everything was ok!

Nessun commento:

Posta un commento