Linux安装maven打包SpringBoot项目踩坑指南

Maven的安装(Ubuntu22.04)

安装maven必须安装java_jdk

apt install openjdk-8-jdk

下载对应版本maven,解压

wget https://mirrors.cnnic.cn/apache/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz --no-check-certificate

tar -zxvf apache-maven-3.5.4-bin.tar.gz

在/usr/local/目录下新建maven文件并将解压文件移动到maven

mkdir /usr/local/maven

mv apache-maven-3.5.4 /usr/local/maven

ln -s /usr/local/maven/bin/mvn /usr/bin/mvn# 与jenkins联合使用时,jenkins会到/usr/bin/下找mvn命令,如果没有会报错

配置maven环境变量

vim /etc/profile

export MAVEN_HOME=/usr/local/maven/apache-maven-3.5.4
export PATH=${PATH}:${MAVEN_HOME}/bin

source /etc/profile
输入mvn测试是否成功

image.png
可使用mvn package命令打包项目

至此maven安装完成

使用maven打包SpringBoot的jar包易发生问题及解决方案

maven换源

进入maven目录

cd /usr/local/maven/apache-maven-3.5.4/conf/

找到settings.xml

在mirrors标签下加入阿里云镜像源

<mirrors>
        <!-- 阿里云仓库 -->
        <mirror>
            <id>alimaven</id>
            <mirrorOf>central</mirrorOf>
            <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
        </mirror>

        <!-- 中央仓库1 -->
        <mirror>
            <id>repo1</id>
            <mirrorOf>central</mirrorOf>
            <name>Human Readable Name for this Mirror.</name>
            <url>http://repo1.maven.org/maven2/</url>
        </mirror>

        <!-- 中央仓库2 -->
        <mirror>
            <id>repo2</id>
            <mirrorOf>central</mirrorOf>
            <name>Human Readable Name for this Mirror.</name>
            <url>http://repo2.maven.org/maven2/</url>
        </mirror>
    </mirrors>

image.png

wq保存即可换源,mvn打包时download飞快

image.png

Maven打包SpringBoot项目时出现Test异常

打包失败异常如下
image.png

1、直接修改 maven 配置命令:

// 不会编译测试
mvn install -Dmaven.test.skip=true

// 忽略测试执行期间发生的任何故障
mvn install -Dmaven.test.failure.ignore=true

2、在项目的 pom.xml 文件中加入如下配置:

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-surefire-plugin</artifactId>
	<version>2.22.2</version>
	<configuration>
		<skipTests>true</skipTests> <!-- 不会编译测试 -->
	</configuration>
</plugin>

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-surefire-plugin</artifactId>
	<version>2.22.2</version>
	<configuration>
		<testFailureIgnore>true</testFailureIgnore> <!-- 忽略测试执行期间发生的任何故障 -->
	</configuration>
</plugin>

注:将代码插入plugins标签下,保存即可
image.png

存在Test错误,但能正常打包

image.png
参考文章
https://blog.csdn.net/qq_26095375/article/details/120859485
https://blog.csdn.net/xhaimail/article/details/107532583
https://www.cnblogs.com/chinaifae/p/10212437.html
https://blog.csdn.net/weixin_43793525/article/details/124074574

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值