'Multiple issues in Log4J Upgrade for old Java Servlet ( Struts ) based application
Current Situation
Java Application development version: a Struts based GUI application developed in Java 1.5 JDK used for Compilation: 1.7 Tomcat Server: Application is hosted on tomcat 6. Current Log4J version: 2.3 Build Tool: Maven 3
Aim
Upgrade Log4J to latest version.
Problem Description
I have tried multiple ways while upgrading but all various combinations of tomcat and Java. But I am encountering different issues. Below is the list of issues.
**JDK 7, Log4j-2.3 Tomcat 6 ( Current Situation) **
Able to build war file, application gets deployed and runs smoothly.
JDK 7 and Tomcat 6 , Log4j- 2.17.1
The war file generated is not having all the classes from the application. ( Quite surprising ). I enabled the debug logs for maven but did not find any surprising entry. I reverted the Log4j version back to 2.3, and things came back to normal. Tried multiple iterations of this, but still the same issue.
JDK 8 and Tomcat 6 , Log4j- 2.17.1
I am able to build war file successfully ( with all the classes) , and deploy it to tomcat. But when I open the landing page of webapp, I am presented with an error: The type java.io.ObjectInputStream cannot be resolved. It is indirectly referenced from required .class files
On investigating I understood that it is not really a bug with JDK 8 as mentioned in many posts, and it is recommended to upgrade the Tomcat version.
JDK 8 and Tomcat 8 , Log4j- 2.17.1
Successfully able to build war file. While deploying it to Tomcat we get below error:
SEVERE [localhost-startStop-1] org.apache.catalina.startup.ContextConfig.processAnnotationsJar Unable to process Jar entry [xxxxxxxx.class] from Jar [jar:file:/C:/xxxx/xxx/xxxx.war!/WEB-INF/lib/client-1.1.jar] for annotations org.apache.tomcat.util.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool: 60
Based on investigation and various posts, we skipped jar scanning for this jar, by adding JarsToSkip in tomcat’s configuration catalina.properties file.
JDK 8 and Tomcat 8 , Log4j- 2.17.1, catalina.properties with jarsToSkip entry for problematic Jar
Able to build war file, and deploy it to Tomcat. Login page opens successfully.
When I submit the login form, application encounters below error: java.lang.NoSuchMethodError: org.apache.catalina.core.StandardContext.findApplicationParameters()[Lorg/apache/catalina/deploy/ApplicationParameter;
Looking at the documentation and code, everything looks fine with method's signature. Quite surprising to have this error.
Tomcat also has catalina.jar, servlet-api.jar files at the right location.
Trying with higher tomcat version.
JDK 8, Tomcat 9, Log4j- 2.17.1, catalina.properties with jarsToSkip entry for problematic Jar
again presented with same error: java.lang.NoSuchMethodError: org.apache.catalina.core.StandardContext.findApplicationParameters()[Lorg/apache/catalina/deploy/ApplicationParameter;
** Tried with Tomcat 10 this time **
Now with this version of tomcat servlet apis are packaged in jakarta.servlet.* package instead of javax.servlet.*
This will need lot of code changes and testing, thus I am avoiding it.
What I am looking for
- Can you help me understand if the overall process I tried is correct or what should be changed?
- Which combination of JDK, and Tomcat should I use to be able to use log4J-2.17.1
- There have been different errors at different combinations, which error should I focus first and try to avoid, to be able to solve this situation.
- Any suggestions on how this error can be solved.
Please let me know if you need any more details around this, to be able to help.
P.S.:
I am fairly new in Java, Struts, Maven, Tomcat tools, and I may have missed some solutions which may seem basic. I am open for various suggestions.
Thanks.
Solution 1:[1]
You should add dependencies for log4j-core and log4j-jc and secondly (in my case) move log4j.properties to log4j2.properties
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | user19039959 |