Tomcat 7 java.lang.NoClassDefFoundError: javax/el/ELManager
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49385257/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Tomcat 7 java.lang.NoClassDefFoundError: javax/el/ELManager
提问by Mister Lamp
I want to deploy my application to a tomcat in version 7 and I get the following Exception java.lang.NoClassDefFoundError: javax/el/ELManager
But if I try to deploy this application to tomcat version 8 it works fine.
我想将我的应用程序部署到版本 7 中的 tomcat,java.lang.NoClassDefFoundError: javax/el/ELManager
但出现以下异常但如果我尝试将此应用程序部署到 tomcat 版本 8,它可以正常工作。
Do you have any ideas how to fix this?
你有什么想法如何解决这个问题吗?
Why do i switch from tomcat 8 to 7? In the test environment was tomcat 8 in the repo and on the server it is tomcat7.
为什么我从 tomcat 8 切换到 7?在测试环境中,repo 中是 tomcat 8,而在服务器上它是 tomcat7。
pom.xml
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>certplatform</groupId>
<artifactId>certplatform</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-
core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.0.4.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-
context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.0.4.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-
context-support -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>5.0.4.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-
webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.0.4.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-web
-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.0.4.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!--https://mvnrepository.com/artifact/javax.servlet.jsp.jstl/javax.servlet.jsp.jstl-api -->
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>javax.servlet.jsp.jstl-api</artifactId>
<version>1.2.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.mail/mail -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.5.0-b01</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-validator -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.8.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.15.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-entitymanager -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.2.15.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk15on -->
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.59</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.bouncycastle/bcpkix-jdk15on -->
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.59</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.el/javax.el-api -->
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>3.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.el/el-api -->
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>2.2</version>
</dependency>
web.xml
网页.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>spring-mvc-demo</display-name>
<!-- Spring MVC Configs -->
<!-- Step 1: Configure Spring MVC Dispatcher Servlet -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-mvc-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Step 2: Set up URL mapping for Spring MVC Dispatcher Servlet -->
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
回答by hovanessyan
The issue is caused by the fact that this class javax/el/ELManager
is introduced in el-api
version 3.0.
该问题是由于该类javax/el/ELManager
是在el-api
3.0 版中引入的。
Tomcat 7 is coming with pre-bundled el-api 2.2(which is missing the class) and it's picking that at runtime, instead of your el-api jar.
Tomcat 7 带有预捆绑的 el-api 2.2(缺少该类),它在运行时选择它,而不是您的 el-api jar。
Tomcat 8 has the el-api 3.0and hence the javax/el/ELManager
class is present.
Tomcat 8 具有 el-api 3.0,因此javax/el/ELManager
存在该类。
It's best if you can sync your dev/test/prod environments as close as possible.
如果您可以尽可能接近地同步您的开发/测试/生产环境,那是最好的。
It makes much more sense to develop against Tomcat 8 in dev, when your test environment has Tomcat 8. As you found out Tomcat 7 and 8 servers comes with different set of libraries, so your code can behave differently against those different set of libraries.
当您的测试环境具有 Tomcat 8 时,在 dev 中针对 Tomcat 8 进行开发会更有意义。正如您发现 Tomcat 7 和 8 服务器带有不同的库集,因此您的代码可以针对这些不同的库集表现不同。
回答by Stephen C
If you want to run your webapp on Tomcat 7 in production, then you should be using Tomcat 7 in your test environment.
如果您想在生产环境中在 Tomcat 7 上运行您的 web 应用程序,那么您应该在您的测试环境中使用 Tomcat 7。
What has happened is that you have accidentally introduced a dependency on the EL 3.0 APIs ... and included it in your POM file. It is working find on Tomcat 8. But on Tomcat 7, the platform supports EL 2.1. So when your app attempts to load the classfile for javax.el.ELManager
... it fails.
发生的事情是您不小心引入了对 EL 3.0 API 的依赖项……并将其包含在您的 POM 文件中。它可以在 Tomcat 8 上找到。但是在 Tomcat 7 上,该平台支持 EL 2.1。因此,当您的应用程序尝试为javax.el.ELManager
...加载类文件时,它会失败。
Solutions:
解决方案:
- Upgrade your production platform to Tomcat 8
- Downgrade your dev and test platforms to Tomcat 7, and eliminate any dependencies on the newer APIs from your codebase .
- 将您的生产平台升级到 Tomcat 8
- 将您的开发和测试平台降级到 Tomcat 7,并从您的代码库中消除对较新 API 的任何依赖。
The Apache Tomcat Versionspage lists the various spec versions for each of the major versions of Tomcat.
该的Apache Tomcat版本页面列出了各种规格的版本,每个Tomcat的主要版本。
Is there no possibility to solve this issue?
有没有可能解决这个问题?
If you were prepared to "butcher" the Tomcat 7 server, you might be able to replace the EL implementation with a newer one. But I would not try that, because 1) it may not work at all, and 2) the result is liable to be difficult to maintain. And you are liable to give your operations, quality assurance and/or security teams an apoplexy!
如果您准备“屠宰”Tomcat 7 服务器,您或许可以用更新的实现替换 EL 实现。但我不会尝试这样做,因为 1) 它可能根本不起作用,以及 2) 结果可能难以维护。而且您有可能让您的运营、质量保证和/或安全团队中风!
Is there no possibility to solve this issue with changes in the application?
是否有可能通过更改应用程序来解决此问题?
AFAIK, there is no possibility.
AFAIK,没有可能性。
I thought you could try replacing the EL dependency with this:
我想你可以尝试用这个替换 EL 依赖:
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>3.0.0</version>
</dependency>
But it doesn't work. According to a comment from Alex:
但它不起作用。根据亚历克斯的评论:
"Adding the JAR to the application POM does not solve anything. Here its the message printed out by Tomcat bootstrap: "validateJarFile(C:\Software\apache-tomcat-7.0.99\webapps\leonardo-flows-services\WEB-INF\lib\javax.el-api-3.0.0.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/el/Expression.class". It conflicts with its lib jar."
“将JAR添加到应用程序POM并不能解决任何问题。这是Tomcat引导程序打印出的消息:“validateJarFile(C:\Software\apache-tomcat-7.0.99\webapps\leonardo-flows-services\WEB-INF \lib\javax.el-api-3.0.0.jar) - jar 未加载。请参阅 Servlet 规范 3.0,第 10.7.2 节。违规类:javax/el/Expression.class”。它与它的 lib jar 冲突。”