0
点赞
收藏
分享

微信扫一扫

spring-boot-maven-plugin 配置是干啥的?

这个是SpringBoot的Maven插件,主要用来打包的,通常打包成jar或者war文件。
其中goal标签可以有5个值:
repackage : 默认值,就是在执行mvn package之后,再次打包,并把第一次生成的包加上后缀.origin
run : 运行SpringBoot应用
start : mvn integration-test,再进行管理
stop : mvn integration-test,再进行管理
build-info : 生成构件信息build-info.properties文件
```html/xml
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>


如果不加上这个插件会出现什么情况呢?
可以看到大小很小只有几KB,说明打包的有问题。
![image.png](https://s2.51cto.com/images/20220806/1659797472214038.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)

加上插件之后,再打包看一下:
可以看到,打包正常了,会出现一个后缀为`.original`的文件,也就是上面第一个打包出来的。
![image.png](https://s2.51cto.com/images/20220806/1659797663917876.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)

可以看到这个插件是非常重要的,在开发过程中是必须要配置的,如上配置其实就够了,但是他还有如下功能:
# 1. 配置打包名称:
```html/xml
<configuration>                   
    <classifier>AppName</classifier><!--指定打包后的文件名-->
</configuration>     

2. 排除指定的jar包依赖:

```html/xml
<excludes>
<exclude>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</exclude>
</excludes>

# 3. 排除spring-boot-devtools依赖
因为如果你自动勾选创建SpringBoot项目之后会自动添加这个依赖,
如果自己管理可以直接删除这个依赖,因为他会被默认打包进去。
```html/xml
            <executions>
                <execution>
                    <id>repackage</id>
                    <configuration>
                        <excludeDevtools>true</excludeDevtools>
                    </configuration>
                </execution>
            </executions>

4. 指定主类

这里就是指定启动类的主类是哪一个,如果提示找不到主类,可以在这里设置一下。
```html/xml
<configuration>
<mainClass>com.jack.onebyone.OneByOneApplication</mainClass>
</configuration>


# 5. 配置profile
配置了之后感觉没啥用,还不会用。
```html/xml
                <configuration>
                    <profiles>
                        <profile>dev</profile>
                    </profiles>
                </configuration>

6. 配置JVM参数

和上面的一样,也不清楚怎么使用。
```html/xml
<configuration>
<jvmArguments>
-Dspring.profiles.active=dev -Xmx500m -Xms500m
</jvmArguments>
</configuration>



其他情况遇到再进行更新,会使用的可以留言哟~
举报

相关推荐

0 条评论