Package a spring boot application including JSPs and static resources

前端 未结 5 2007
面向向阳花
面向向阳花 2020-12-29 11:46

I want to package a spring-boot application as jar, and I do so with mvn package.

This produces a jar which does not contain any /WEB-INF/jsp

相关标签:
5条回答
  • 2020-12-29 12:11

    I had the same problem you had. I tried the answer above that you marked correct but it didn't work for me.

    This worked ... change the pom.xml to ...

    <packaging>war</packaging>
    

    ... this will causes maven to create a WAR file that is executable like so ...

    java -jar yourwarfile.war
    

    I found this solution with this similar question here ...

    WEB-INF not included in WebApp using SpringBoot, Spring-MVC and Maven

    0 讨论(0)
  • 2020-12-29 12:19

    To create a runnable JAR with Spring Boot, use the spring-boot-maven-plugin in your pom.xml

    <build>
    <plugins>
        <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
    </build>
    

    Maybe you want to have a look at my example application http://info.michael-simons.eu/2014/02/20/developing-a-web-application-with-spring-boot-angularjs-and-java-8/ (Source is on GitHub, App is live and runs from a JAR).

    One thing that you should note: JSP from JAR doesn't work due to some embedded Tomcat problems. I'm using Thymeleaf. If you need JSP, stay with the WAR deployment.

    0 讨论(0)
  • 2020-12-29 12:25

    Is there any reason why you can't use the war packaging type? https://maven.apache.org/plugins/maven-war-plugin/usage.html I would recommend to use the war packaging type and use default maven web-application structure.

    If you really want to use the jar plugin for your webapp, you need to configure it for your project. Due to your posting, I don't understand your structure and can't give you an example. Check out the usage of jar plugin here:https://maven.apache.org/plugins/maven-war-plugin/usage.html

    0 讨论(0)
  • 2020-12-29 12:29

    The following example works with Spring Boot 1.3.3.RELEASE: https://github.com/ghillert/spring-boot-jsp-demo

    The key is to put the static jsp content in:

    /src/main/resources/META-INF/resources/WEB-INF/jsp
    

    and ensure you define the view prefix/suffix in your application.properties:

    spring.mvc.view.prefix=/WEB-INF/jsp/
    spring.mvc.view.suffix=.jsp
    
    0 讨论(0)
  • 2020-12-29 12:31

    Change your build tag to

     <build>
    <resources>
                <resource>
                    <directory>${basedir}/src/main/webapp</directory>
                    <includes>
                        <include>**/**</include>
                    </includes>
                </resource>
                <resource>
                    <directory>${basedir}/src/main/resources</directory>
                    <includes>
                        <include>**/**</include>
                    </includes>
                </resource>
            </resources>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <configuration>
                        <useSystemClassLoader>false</useSystemClassLoader>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    
    0 讨论(0)
提交回复
热议问题