Tuesday, April 6, 2010

Migrating from Grails 1.1.1 to 1.2.1

1. Case: Using an xml-rpc-client. Dependencies are listed as below.
xmlrpc-client-3.1.jar -> xmlrpc-common-3.1.jar->ws-commons-util-1.0.2.jar->xml-apis-1.3.03.jar.

I had such a Grails 1.1.1 application. Wanted to upgrade to 1.2.1
Executed grails clean ->grails upgrade.
Added BuildConfig.groovy stating xmlrpc jars as dependencies.
Removed ivy.xml/ivyconf.xml/ivysettings.xml. Uninstalled ivy plugin(if exists)
After this, running any of the grails scripts triggered dependency resoltion using grails 1.2.1's internal ivy mechanism. This looked at the buildConfig and started downloading xml-rpc jars and their dependencies.
After resolution completes, (for any grails script) we get
grails java.lang.LinkageError: loader constraints violated when linking org/xml/sax/Parser class

Solution:
Don't let ws-commons-util-1.0.2.jar and xml-apis-1.3.03.jar be together in same environment.
Remove dependency xml-rpc-client/server from buildConfig.groovy. Copy corresponding files to lib folder of app manually(xmlrpc-client-3.1.jar -> xmlrpc-common-3.1.jar->ws-commons-util-1.0.2.jar). DOOOOONOT add xml-apis-1.3.03.jar. The exception goes away. If i try to use inbuilt resolution for the xml -rppc jars, ivy always fetches ws-commons-util-1.0.2.jar followed by its dependency xml-apis-1.3.03.jar

http://n4.nabble.com/org-apache-xerces-jaxp-SAXParserImpl-getParser-Lorg-xml-sax-Parser-Error-trying-to-include-compile-o-td1695193.html : haven't tried this yet

OR

Use "excludes" mechanism while specifying xmlrpc jar dependencies in BuildConfig

2. Getting "java.lang.NoSuchMethodError:
org.codehaus.groovy.grails.commons.GrailsApplication.getClassLoader()Lgroovy/lang/GroovyClassLoader;" when application tries to start.
http://n4.nabble.com/1-2RC2-Error-creating-bean-with-name-sessionFactory-td1322056.html

For me, it happened because I use Ivy plugin's "get-dependencies" script explicitly to resolve dependencies. This fetched all jars into app's lib folder. Some of them might be causing the problem.(GrailsApplication.getClassLoader() was changed from returning GroovyClassLoader to ClassLoader for 1.2)
Solved it by deleting all the jars from lib folder and adding BuildConfig.groovy to grails-app/conf. Grails-1.2.1 handled the dependencies itself using its internal ivy.

3. App build successfully but when tomcat tries to start it throws
org.springframework.beans.factory.access.BootstrapException: Error executing bootstraps; nested exception is java.lang.NoSuchMethodError: javax.servlet.ServletContext.getContextPath()Ljava/lang/String;


http://youtrack.jetbrains.net/issue/IDEA-27215: There's a comment saying that
the method javax.servlet.ServletContext.getContextPath()Ljava/lang/String was added in servlet-api-2.5.jar. It's not present in the 2.4 version. Grails must be somehow loading the ServletContext class from 2.4 instead of 2.5.

Solution: Add 'javax.servlet:servlet-api:2.5' as build dependency in BuildConfig.groovy


4. If you have a hasOne relationship from domain class A to B that is supposed to be nullable, then you need to explicitly specify it as nullable in class A constraints for Grails 1.2.1. It worked without the constraint in Grails-1.1.1.

No comments:

Post a Comment