1

My goal is to build an executable JAR with an embedded Tomcat server to run my Spring MVC application.

You can view a screenshot of my project directory structure here: https://i.sstatic.net/zSoe1.png

When I run "mvn clean install", a new JAR is generated and is runnable. I execute the JAR and see the Spring message and all my endpoints fly by.

When I attempt to go to localhost:8080/ANYENDPOINT, I see a generic 404 page provided by Spring (telling me that I don't have a /error endpoint mapped).

Looking at the logs, I get the following error:

2015-03-17 16:27:10.948  INFO 12160 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]:Initializing Spring FrameworkServlet 'dispatcherServlet' 2015-03-17 16:27:10.949  INFO 12160 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started 
2015-03-17 16:27:10.987  INFO 12160 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet :FrameworkServlet 'dispatcherServlet': initialization completed in 38 ms 2015-03-17 16:27:11.085  WARN 12160 --- [nio-8080-exec-1] o.s.web.servlet.PageNotFound : No mapping found for HTTP request with URI [/WEB-INF/jsp/homepage.jsp] in DispatcherServlet with name 'dispatcherServlet'

It can't see my 'homepage.jsp'. But if you look at my directory structure, it is there. However, when I look at the contents of my built JAR, I see that none of the static files from my project made it to my JAR. Here is a screenshot of the contents of the compiled JAR: https://i.sstatic.net/asA6k.png

I'd like to have my 'webapp' folder included in the built JAR and usable by my Spring app to avoid the error I detailed above.

I am very new to this whole deployment thing. I've always just did development work in Eclipse, verified changes on an external Tomcat server, and pushed code. Now I'd like to learn how to fight the Deployment Monster. Please let me know if anything I'm doing is just plain silly.

A link to a step-by-step resource related to my issue would be helpful too.

Here is my POM:

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.github.xxxx</groupId>
    <artifactId>xxxx</artifactId>
    <packaging>jar</packaging>
    <version>1.8-SNAPSHOT</version>
    <name>Maven Webapp</name>
    <url>http://maven.apache.org</url>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.2.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.2.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.1.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.3.2</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
        </dependency>
        <!-- Spring Security -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>
    </dependencies>
    <build>
        <finalName>StudentEnrollmentWithMyBatis</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.2.2</version>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-scm-plugin</artifactId>
                        <version>1.8.1</version>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
1
  • You are using Spring Boot aren't you?
    – geoand
    Commented Mar 17, 2015 at 20:56

1 Answer 1

2

The way you have structured your application is not correct for creating an executable jar using Spring Boot.

As is stated in this part of the Spring Boot documentation, you need to move you static assets to one of: /static, /public, /resources, /META-INF/resources

Also Embedded servlet containers don't play too smoothly with JSPs as is mentioned here. I suggest you use one the templated engines that are supported seamlessly out of the box.

Not the answer you're looking for? Browse other questions tagged or ask your own question.