简体   繁体   English

spring 启动 maven 不 package ZEC407CCE6B649DAA8E320157EZjar6 文件

[英]spring boot maven doesn't package jsp files to “fat jar”

i'm using project structure from guides, store css & js in static folder in resources and jsp files in webapp/WEB-INF/jsp/我正在使用指南中的项目结构,将 css 和 js 存储在资源的 static 文件夹中,并将 jsp 文件存储在 webapp/WEB-INF/jsp/

but when i build my spring boot application to fat jar by "maven package" task in eclipse it doesn't package all webapp folder to the jar but when i build my spring boot application to fat jar by "maven package" task in eclipse it doesn't package all webapp folder to the jar

my project structure click我的项目结构点击

my pom.xml我的 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.2.5.RELEASE</version>
        <relativePath/>
    </parent>
    <groupId>ru.pa4ok</groupId>
    <artifactId>csplatform</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>csplatform</name>
    <description>Remote studing web service</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </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>

        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>
    </dependencies>

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

</project>

There is a " JSP limitation " in spring boot when done Jar packaging.完成 Jar 包装后,在 spring 引导中存在“ JSP 限制”。 In the official documentation it says as在官方文档中它说

Do not use the src/main/webapp folder if your application will be packaged as a jar.如果您的应用程序将被打包为 jar,请不要使用 src/main/webapp 文件夹。 Although this folder is a common standard, it will only work with war packaging and it will be silently ignored by most build tools if you generate a jar.尽管此文件夹是通用标准,但它仅适用于 war 打包,并且如果您生成 jar,大多数构建工具都会默默地忽略它。

For more info read here 欲了解更多信息,请阅读此处

So your webapp directory is getting ignored with fat jar packaging.因此,您的 webapp 目录被胖 jar 包装所忽略。

One alternate is to change the packaging to war and execute as how you execute a jar file.一种替代方法是将打包更改为 war 并按照执行 jar 文件的方式执行。

Other alternate which could also work is to add the spring boot maven plugin with following.其他也可以工作的替代方法是添加 spring 引导 maven 插件,如下所示。

<build>
     <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.2.6.RELEASE</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

If either of them doesn't work for you, please follow this link to more answers:如果其中任何一个都不适合您,请点击此链接获取更多答案:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM