others-how to solve `Unable to process Jar entry [META-INF/versions/9/module-info.class` when trying to start tomcat webapp?

1. Purpose

In this post, I will demonstrate how to solve Unable to process Jar entry [META-INF/versions/9/module-info.class when trying to start tomcat:


Oct 05, 2022 10:04:00 AM org.apache.catalina.startup.ContextConfig processAnnotationsJar
Severe: Unable to process Jar entry [META-INF/versions/9/module-info.class] from Jar [jar:file:/opt/tomcat/webapps/myapp/WEB-INF/lib/bcprov-jdk15on-1.62.jar!/] for annotations
org.apache.tomcat.util.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool: 19
    at org.apache.tomcat.util.bcel.classfile.Constant.readConstant(Constant.java:133)
    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:2105)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1981)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1947)
    at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1932)
    at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1326)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:878)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:369)
    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:5179)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1114)
    at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1673)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)



2. Solution

2.1 Solution 1

The reason for this problem is that some jars have added jdk9 feature Module and Package information. In these packages, you can find module-info.class, and its jdk version number also corresponds to 1.9.

For example, the affected jars in my project are bcprov-jdk15on-1.62.jar etc., and other class file versions in these packages The number has not been upgraded to 1.9, and when tomcat starts, it will try to parse these classes, and when it parses to module-info.class, an error is reported.

The solution is to upgrade tomcat to the latest version of 8.0, such as 8.5, 9.0

This was a Tomcat bug(https://bz.apache.org/bugzilla/show_bug.cgi?id=60688) that resurfaced again with the Java 9 bytecode. The exact versions which fix this (for both Java 8/9 bytecode) are:

trunk for 9.0.0.M18 onwards 8.5.x for 8.5.12 onwards 8.0.x for 8.0.42 onwards 7.0.x for 7.0.76 onwards

So my solution to this problem is:

Upgrade my tomcat version from 7.0.0 to 7.0.109, it works!



3. Summary

In this post, I demonstrated how to solve Unable to process Jar entry [META-INF/versions/9/module-info.class problem, the key point is to upgrade your tomcat to proper version. That’s it, thanks for your reading.