Spring Boot项目打包

一 打包方式
1 构建JAR包
2 构建WAR包
3 指定Main-Class

二 打jar包
1 cmd进入指定项目
2 打包
mvn -Dmaven.test.skip -U clean package
结果打包失败
修改主pom文件
增加mainClass部分
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>com.imooc.firstappdemo.FirstAppDemoApplication</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
重新打包,依然失败
根据提示,修改主pom文件,增加依赖部分
    
<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <dependencies>
                    <dependency>
                        <groupId>com.imooc</groupId>
                        <artifactId>model</artifactId>
                        <version>0.0.1-SNAPSHOT</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <mainClass>com.imooc.firstappdemo.FirstAppDemoApplication</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
重新打包,依然失败
换另外一种打包方式
mvn -Dmaven.test.skip -U clean install
依然失败
应该将下面build代码放入到web的pom中,因为web已经变成了项目的主模块
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>com.imooc.firstappdemo.FirstAppDemoApplication</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
用 mvn -Dmaven.test.skip -U clean package 再次打包,打包成功
三 jar包启动,启动成功
四 测试
五 war打包方式
<?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.0http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>first-app-demo</artifactId>
        <groupId>com.imooc</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>web</artifactId>
    <!--將packaging值(默认:jar)调整成war
    -->
    <packaging>war</packaging>
    <!--web依赖于persistence-->
    <!--增加persistence依赖-->
    <dependencies>
        <dependency>
            <groupId>com.imooc</groupId>
            <artifactId>persistence</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>com.imooc.firstappdemo.FirstAppDemoApplication</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>


</project>
 六 执行打包命令
mvn -Dmaven.test.skip -U clean package
出现错误
根据错误提示,增加相关文件
再次执行打包,打包成功
启动程序,启动成功
七 测试
用postman测试,测试成功

八 参考



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值