基于旧 Java Servlet (Struts) 的应用程序的 Log4J 升级中的多个问题
现状
Java应用程序开发版本:Java 1.5开发的基于Struts的GUI应用程序 编译使用的JDK:1.7 Tomcat 服务器:应用程序托管在 tomcat 6 上。 当前 Log4J 版本:2.3 构建工具:Maven 3
目标
将Log4J升级到最新版本。
问题描述
我在升级时尝试了多种方法,但都是tomcat和Java的各种组合。但我遇到了不同的问题。 以下是问题列表。
**JDK 7,Log4j-2.3 Tomcat 6(当前情况)**
能够构建war文件,应用程序部署并顺利运行。
JDK 7 和 Tomcat 6、Log4j-2.17.1
生成的 war 文件不包含应用程序中的所有类。 (相当令人惊讶)。 我启用了 Maven 的调试日志,但没有发现任何令人惊讶的条目。 我将 Log4j 版本恢复到 2.3,一切恢复正常。 尝试了多次迭代,但仍然是同样的问题。
JDK 8和Tomcat 6,Log4j-2.17.1
我能够成功构建war文件(包含所有类),并将其部署到tomcat。但是当我打开webapp的登陆页面时,出现错误: 无法解析 java.io.ObjectInputStream 类型。它是从所需的.class文件间接引用的。
经过调查,我了解到这并不是很多帖子中提到的JDK 8的错误,建议升级Tomcat版本。
JDK 8和Tomcat 8,Log4j-2.17.1
成功构建war文件。 将其部署到 Tomcat 时,我们收到以下错误:
SEVERE [localhost-startStop-1] org.apache.catalina.startup.ContextConfig.processAnnotationsJar 无法处理 Jar [jar:file:/C:/ 中的 Jar 条目 [xxxxxxxx.class] xxxx/xxx/xxxx.war!/WEB-INF/lib/client-1.1.jar] 用于注释 org.apache.tomcat.util.bcel.classfile.ClassFormatException:常量池中无效的字节标记:60
根据调查和各种帖子,我们通过在 tomcat 的配置 catalina.properties 文件中添加 JarsToSkip 跳过了对此 jar 的 jar 扫描。
JDK 8 和 Tomcat 8、Log4j- 2.17.1、catalina.properties,其中包含有问题的 Jar 的 jarsToSkip 条目
能够构建 war 文件,并将其部署到 Tomcat。 登录页面成功打开。
当我提交登录表单时,应用程序遇到以下错误: java.lang.NoSuchMethodError: org.apache.catalina.core.StandardContext.findApplicationParameters()[Lorg/apache/catalina/deploy/ApplicationParameter;
查看文档和代码,方法签名一切看起来都很好。 出现这个错误真是令人惊讶。
Tomcat 在正确的位置也有 catalina.jar、servlet-api.jar 文件。
尝试使用更高版本的tomcat。
JDK 8、Tomcat 9、Log4j- 2.17.1、catalina.properties 以及有问题的 Jar 的 jarsToSkip 条目
再次出现相同的错误: java.lang.NoSuchMethodError: org.apache.catalina.core.StandardContext.findApplicationParameters()[Lorg/apache/catalina/deploy/ApplicationParameter;
** 这次尝试使用 Tomcat 10 **
现在有了这个tomcat servlet api 的版本打包在 jakarta.servlet.* 包中,而不是 javax.servlet.*
这将需要大量的代码更改和测试,因此我我正在回避它。
我在寻找什么
- 您能帮助我了解我尝试的整个过程是否正确或应该更改哪些内容?
- 我应该使用JDK和Tomcat的哪种组合才能使用log4J-2.17.1
- 不同的组合出现了不同的错误,我应该首先关注并尽量避免哪个错误,才能解决这种情况。
- 有关如何解决此错误的任何建议。
如果您需要更多详细信息,请告诉我,以便能够提供帮助。
PS:
我对 Java、Struts、Maven、Tomcat 工具相当陌生,我可能错过了一些看似基本的解决方案。我愿意接受各种建议。
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该添加 log4j-core 和 log4j-jc 的依赖项,其次(在我的例子中)将 log4j.properties 移动到 log4j2.properties
You should add dependencies for log4j-core and log4j-jc and secondly (in my case) move log4j.properties to log4j2.properties