英文:
Getting Error java.lang.ClassNotFoundException: javax.servlet.jsp.jstl.core.Config
问题
I am developing a spring boot project. The code works perfectly fine on localhost in IntelliJ.
The war file was created using the command
mvn clean install
But when I run it on the CentOS server with the command
java -jar app.war
On running the above command, the deployment successfully starts at port 8080.
But the problem occurs when any page containing JSTL JSP is accessed. It displays a 404 error, and the following error is visible in the log. This code was working perfectly fine a few days ago, but now I can't understand what changed, except I made a few code changes and deployed the new WAR file. I haven't changed anything in pom.xml
.
2020-07-31 13:37:27.382 ERROR 5141 --- [nio-8080-exec-8] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] threw exception
java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config
at org.springframework.web.servlet.support.JstlUtils.exposeLocalizationContext(JstlUtils.java:103) ~[spring-webmvc-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at org.springframework.web.servlet.view.JstlView.exposeHelpers(JstlView.java:137) ~[spring-webmvc-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:145) ~[spring-webmvc-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:316) ~[spring-webmvc-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1373) ~[spring-webmvc-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1118) ~[spring-webmvc-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1057) ~[spring-webmvc-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) ~[spring-webmvc-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) ~[spring-webmvc-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:634) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:320) ~[spring-security-web-5.3.3.RELEASE.jar!/:5.3.3.RELEASE]
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:115) ~[spring-security-web-5.3.3.RELEASE.jar!/:5.3.3.RELEASE]
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:90) ~[spring-security-web-5.3.3.RELEASE.jar!/:5.3.3.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) ~[spring-security-web-5.3.3.RELEASE.jar!/:5.3.3.RELEASE]
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:118) ~[spring-security-web-5.3.3.RELEASE.jar!/:5.3.3.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) ~[spring-security-web-5.3.3.RELEASE.jar!/:5.3.3.RELEASE]
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:84) ~[spring-security-web-5.3.3.RELEASE.jar!/:5.3.3.RELEASE]
英文:
I am developing a spring boot project. The code works perfectly fine on localhost in intelliJ.
The war file was created using command
mvn clean install
But when I run it on centos server with command
java -jar app.war
On running above command the deploy is successfully started at port 8080
But the problem occurs when any page containing jstl jsp is access. It displays 404 error
following error is visible on log. This code was working perfectly fine few days ago but now I cant get what changed except I made few code changes and deployed the new war file. I haven't changed anything in pom.xml.
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
2020-07-31 13:37:27.382 ERROR 5141 --- [nio-8080-exec-8] o.a.c.c.C.[.[.[/].[disp atcherServlet] : Servlet.service() for servlet [dispatcherServlet] threw exce ption
java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config
at org.springframework.web.servlet.support.JstlUtils.exposeLocalizationC ontext(JstlUtils.java:103) ~[spring-webmvc-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at org.springframework.web.servlet.view.JstlView.exposeHelpers(JstlView. java:137) ~[spring-webmvc-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at org.springframework.web.servlet.view.InternalResourceView.renderMerge dOutputModel(InternalResourceView.java:145) ~[spring-webmvc-5.2.7.RELEASE.jar!/: 5.2.7.RELEASE]
at org.springframework.web.servlet.view.AbstractView.render(AbstractView .java:316) ~[spring-webmvc-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherSe rvlet.java:1373) ~[spring-webmvc-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.processDispatchResu lt(DispatcherServlet.java:1118) ~[spring-webmvc-5.2.7.RELEASE.jar!/:5.2.7.RELEAS E]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(Dispatch erServlet.java:1057) ~[spring-webmvc-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(Dispatche rServlet.java:943) ~[spring-webmvc-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(Frame workServlet.java:1006) ~[spring-webmvc-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServl et.java:898) ~[spring-webmvc-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:634) ~[tomcat -embed-core-9.0.36.jar!/:9.0.36]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkSer vlet.java:883) ~[spring-webmvc-5.2.7.RELEASE.jar!/:5.2.7.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) ~[tomcat -embed-core-9.0.36.jar!/:9.0.36]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl icationFilterChain.java:231) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF ilterChain.java:166) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain. doFilter(FilterChainProxy.java:320) ~[spring-security-web-5.3.3.RELEASE.jar!/:5. 3.3.RELEASE]
at org.springframework.security.web.access.intercept.FilterSecurityInter ceptor.invoke(FilterSecurityInterceptor.java:115) ~[spring-security-web-5.3.3.RE LEASE.jar!/:5.3.3.RELEASE]
at org.springframework.security.web.access.intercept.FilterSecurityInter ceptor.doFilter(FilterSecurityInterceptor.java:90) ~[spring-security-web-5.3.3.R ELEASE.jar!/:5.3.3.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain. doFilter(FilterChainProxy.java:334) ~[spring-security-web-5.3.3.RELEASE.jar!/:5. 3.3.RELEASE]
at org.springframework.security.web.access.ExceptionTranslationFilter.do Filter(ExceptionTranslationFilter.java:118) ~[spring-security-web-5.3.3.RELEASE. jar!/:5.3.3.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain. doFilter(FilterChainProxy.java:334) ~[spring-security-web-5.3.3.RELEASE.jar!/:5. 3.3.RELEASE]
at org.springframework.security.web.session.SessionManagementFilter.doFi lter(SessionManagementFilter.java:84) ~[spring-security-web-5.3.3.RELEASE.jar!/: 5.3.3.RELEASE]
<!-- end snippet -->
pom.xml
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.appl</groupId>
<artifactId>appl</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>appll</name>
<description>APP Search project for</description>
<packaging>war</packaging>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.hibernate </groupId>-->
<!-- <artifactId>hibernate-ehcache</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.darrachequesne</groupId>
<artifactId>spring-data-jpa-datatables</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
<!-- end snippet -->
> I tried both the ways w/ and w/o provided
答案1
得分: 1
问题在于您在servlet中使用了"provided"范围。"provided"范围意味着它将用于构建和测试,但不用于运行时,因为它将由运行时环境(容器、特定服务器等)提供。如果您想要在命令行中运行它,应该删除范围。
英文:
I think the problem here is that you are using the "provided" scope for your servlet. The provided scope means it will be used for build and testing but not for runtime, as it will be provided by the runtime environment (container, specific server..). You should remove the scope if you want to run it with cli.
答案2
得分: 1
Sure, here is the translated content:
不能在容器外部运行war文件。从POM中删除<packaging>war</packaging>,这将将打包设置为默认值(jar)。
然后在CentOS中使用以下命令运行项目。
- java -jar app.jar
另一种解决方案是在CentOS中安装容器,然后将War部署到容器中。
英文:
It is not possible to run a war file outside of a container.Remove <packaging>war</packaging> from POM this will set packaging to default(jar).
Then use below command in CentOS to run the project.
- java -jar app.jar
The other solution is to install a container in CentOS and then deploy the War to it.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论