The Bad Programmer

Deploy Grails 3 Application to Tomcat 7.0.37



I had some issues getting a Grails 3 application to deploy to Tomcat 7.0.37. I finally figured out that the problem was that I was running Tomcat with a 1.8 JDK. If you try to deploy a Grails 3 application to Tomcat 7.0.37 running with a Java 1.8 JDK you get an error that looks like this when the application is deploying:

Caused by: org.apache.tomcat.util.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool: 18
    at org.apache.tomcat.util.bcel.classfile.Constant.readConstant(Constant.java:131)
    at org.apache.tomcat.util.bcel.classfile.ConstantPool.<init>(ConstantPool.java:60)
    at org.apache.tomcat.util.bcel.classfile.ClassParser.readConstantPool(ClassParser.java:209)
    at org.apache.tomcat.util.bcel.classfile.ClassParser.parse(ClassParser.java:119)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2032)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1923)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1891)
    at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1877)
    at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1270)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:855)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:345)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5161)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)

I should note that my app was compiled with source compatibility set at 1.7 so it should have had no problem running under a 1.8 JDK. I have had no other problems running Tomcat 7.0.37 under Java 1.8.

I have no idea if later dot releases of Tomcat 7 have the same problem but it is definitely a problem with Tomcat 7.0.37. From looking at the stack trace it looks like there is some deploy time processing of annotations and whatever is doing that processing doesn’t like running under Java 1.8.

Here is a table of my testing with Tomcat 7.0.37 and an Grails 3 application:

JDK Source Deploys?
1.8 1.7 Nope
1.8 1.8 Nope
1.7 1.7 Yes!
1.7 1.8 Nope, however it is obvious this one won’t work, just including for completeness