skip to Main Content

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.

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]

pom.xml

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

I tried both the ways w/ and w/o provided

2

Answers


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

    Login or Signup to reply.
  2. It is not possible to run a war file outside of a container.Remove war 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search