Getting Error java.lang.ClassNotFoundException: javax.servlet.jsp.jstl.core.Config

huangapple go评论79阅读模式
英文:

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 -->

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
	xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
	&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
	&lt;parent&gt;
		&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
		&lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
		&lt;version&gt;2.3.1.RELEASE&lt;/version&gt;
		&lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
	&lt;/parent&gt;
	&lt;groupId&gt;com.appl&lt;/groupId&gt;
	&lt;artifactId&gt;appl&lt;/artifactId&gt;
	&lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
	&lt;name&gt;appll&lt;/name&gt;
	&lt;description&gt;APP Search project for&lt;/description&gt;
	&lt;packaging&gt;war&lt;/packaging&gt;
	&lt;properties&gt;
		&lt;java.version&gt;1.8&lt;/java.version&gt;
	&lt;/properties&gt;

	&lt;dependencies&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;ch.qos.logback&lt;/groupId&gt;
			&lt;artifactId&gt;logback-classic&lt;/artifactId&gt;
			&lt;scope&gt;compile&lt;/scope&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
			&lt;artifactId&gt;log4j-to-slf4j&lt;/artifactId&gt;
			&lt;scope&gt;compile&lt;/scope&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.slf4j&lt;/groupId&gt;
			&lt;artifactId&gt;jul-to-slf4j&lt;/artifactId&gt;
			&lt;scope&gt;compile&lt;/scope&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.slf4j&lt;/groupId&gt;
			&lt;artifactId&gt;log4j-over-slf4j&lt;/artifactId&gt;
			&lt;scope&gt;compile&lt;/scope&gt;
		&lt;/dependency&gt;

		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-data-rest&lt;/artifactId&gt;
		&lt;/dependency&gt;
&lt;!--		&lt;dependency&gt;--&gt;
&lt;!--			&lt;groupId&gt;org.hibernate &lt;/groupId&gt;--&gt;
&lt;!--			&lt;artifactId&gt;hibernate-ehcache&lt;/artifactId&gt;--&gt;
&lt;!--		&lt;/dependency&gt;--&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;mysql&lt;/groupId&gt;
			&lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
			&lt;scope&gt;runtime&lt;/scope&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;/artifactId&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-tomcat&lt;/artifactId&gt;
			&lt;scope&gt;provided&lt;/scope&gt;

		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-validation&lt;/artifactId&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.apache.tomcat.embed&lt;/groupId&gt;
			&lt;artifactId&gt;tomcat-embed-jasper&lt;/artifactId&gt;
		&lt;/dependency&gt;
	  &lt;dependency&gt;
		&lt;groupId&gt;javax.servlet&lt;/groupId&gt;
		&lt;artifactId&gt;jstl&lt;/artifactId&gt;
		&lt;scope&gt;provided&lt;/scope&gt;

	&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;com.github.darrachequesne&lt;/groupId&gt;
			&lt;artifactId&gt;spring-data-jpa-datatables&lt;/artifactId&gt;
			&lt;version&gt;5.0.0&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
			&lt;artifactId&gt;lombok&lt;/artifactId&gt;
			&lt;version&gt;1.18.12&lt;/version&gt;
			&lt;scope&gt;provided&lt;/scope&gt;
		&lt;/dependency&gt;

		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-mail&lt;/artifactId&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.thymeleaf.extras&lt;/groupId&gt;
			&lt;artifactId&gt;thymeleaf-extras-springsecurity5&lt;/artifactId&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
			&lt;scope&gt;test&lt;/scope&gt;
			&lt;exclusions&gt;
				&lt;exclusion&gt;
					&lt;groupId&gt;org.junit.vintage&lt;/groupId&gt;
					&lt;artifactId&gt;junit-vintage-engine&lt;/artifactId&gt;
				&lt;/exclusion&gt;
			&lt;/exclusions&gt;
		&lt;/dependency&gt;
	&lt;/dependencies&gt;

	&lt;build&gt;
		&lt;plugins&gt;
			&lt;plugin&gt;
				&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
				&lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
			&lt;/plugin&gt;
		&lt;/plugins&gt;
	&lt;/build&gt;

&lt;/project&gt;

<!-- 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中使用以下命令运行项目。

  1. 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.

  1. java -jar app.jar

The other solution is to install a container in CentOS and then deploy the War to it.

huangapple
  • 本文由 发表于 2020年7月31日 16:22:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/63188265.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定