springboot將jsp打包成jar執行的坑

litblank發表於2018-08-14

springboot中整合jsp,打成jar包可用jsp

  • blog.csdn.net/qq_34665539…
  • spring-boot-maven-plugin 1.5.3版本的打包控制元件打出來的jar包是無法訪問jsp的,直接404
  • spring-boot-maven-plugin 1.4.2版本就是可以的
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.idp</groupId>
    <artifactId>UM-BOSS</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>
    <name>com.boot.web</name>
    <url>http://maven.apache.org</url>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.1.RELEASE</version>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>

    <distributionManagement>
        <repository>
            <id>nexus-public-snapshots</id>
            <url>http://10.20.69.85:8081/nexus/content/groups/public-snapshots</url>
        </repository>
        <snapshotRepository>
            <id>nexus</id>
            <url>http://10.20.69.85:8081/nexus/content/groups/public</url>
        </snapshotRepository>
    </distributionManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <!--   <scope>provided</scope>-->
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <!--   <scope>provided</scope>-->
        </dependency>
    </dependencies>
    <!-- Maven控制Spring Profile -->
    <profiles>
        <profile>
            <id>dev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <profileActive>dev</profileActive>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </dependency>
                <dependency>
                    <groupId>org.apache.tomcat</groupId>
                    <artifactId>tomcat-jdbc</artifactId>
                </dependency>
                <dependency>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>2.6</version>
                </dependency>
            </dependencies>
        </profile>
        <profile>
            <id>prod</id>
            <properties>
                <profileActive>prod</profileActive>
            </properties>
        </profile>
    </profiles>
    <build>
        <finalName>UM-BOSS</finalName>
        <defaultGoal>clean compile</defaultGoal>
        <resources>
            <!--將jsp打包-->
            <resource>
                <!-- 指定resources外掛處理哪個目錄下的資原始檔 -->
                <directory>src/main/webapp</directory>
                <!--注意此次必須要放在此目錄下才能被訪問到-->
                <targetPath>META-INF/resources</targetPath>
                <includes>
                    <include>**/**</include>
                </includes>
            </resource>
            <!--編譯時將resources打包-->
            <resource>
                <directory>src/main/resources</directory>
                <!-- 是否替換@xx@表示的maven properties屬性值 -->
                <filtering>false</filtering>
                <includes>
                    <include>**/**</include>
                </includes>
            </resource>
            <!--mybatis檔案的XML,載入到編譯檔案中-->
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>com/idp/web/**/**/*.xml</include>
                </includes>
            </resource>

        </resources>
        <plugins>
            <!--編譯版本-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <!--配置jar包啟動-->
           <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>1.4.2.RELEASE</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>com.ApplicationContext</mainClass>
                    <layout>JAR</layout>
                </configuration>
            </plugin>
        <!--    <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                </configuration>
            </plugin>-->
        </plugins>
    </build>
</project>
複製程式碼

相關文章