Centos7 maven 安装

maven 下载省略

sudo mkdir -p /usr/local/maven

tar -zxvf apache-maven-3.9.10-bin.tar.gz -C /usr/local/maven/

/usr/local/maven/apache-maven-3.9.10/bin

sudo vi /etc/profile.d/maven.sh

export JAVA_HOME=/usr/lib/jvm/jdk-17

export M2_HOME=/usr/local/maven/apache-maven-3.9.10

export MAVEN_HOME=/usr/local/maven/apache-maven-3.9.10

export PATH={M2_HOME}/bin:{PATH}

source /etc/profile

或者重新登录

mvn -version

代码中使用时,在pom.xml中配置

jdk 8 版本

<build>

<plugins>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-compiler-plugin</artifactId>

<version>3.8.1</version>

<configuration>

<source>1.8</source>

<target>1.8</target>

<fork>true</fork>

<executable>${JAVA_HOME}/bin/javac</executable>

</configuration>

</plugin>

</plugins>

</build>

=================================================

jdk 17 的基本配置

<build>

<plugins>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-compiler-plugin</artifactId>

<version>3.11.0</version>

<configuration>

<source>17</source>

<target>17</target>

<encoding>UTF-8</encoding>

</configuration>

</plugin>

</plugins>

</build>

在上一步的基础上,指定JDK路径的配置

<build>

<plugins>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-compiler-plugin</artifactId>

<version>3.11.0</version>

<configuration>

<source>17</source>

<target>17</target>

<fork>true</fork>

<executable>${JAVA_HOME}/bin/javac</executable>

<encoding>UTF-8</encoding>

</configuration>

</plugin>

</plugins>

</build>

完整配置(包含编译器参数)

<build>

<plugins>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-compiler-plugin</artifactId>

<version>3.11.0</version>

<configuration>

<source>17</source>

<target>17</target>

<fork>true</fork>

<executable>${JAVA_HOME}/bin/javac</executable>

<encoding>UTF-8</encoding>

<compilerArgs>

<arg>-parameters</arg>

<arg>-Xlint:unchecked</arg>

<arg>-Xlint:deprecation</arg>

</compilerArgs>

<showWarnings>true</showWarnings>

<showDeprecation>true</showDeprecation>

</configuration>

</plugin>

</plugins>

</build>

多版本兼容配置(如果需要)

<build>

<plugins>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-compiler-plugin</artifactId>

<version>3.11.0</version>

<configuration>

<source>17</source>

<target>17</target>

<fork>true</fork>

<executable>${env.JAVA_HOME_17}/bin/javac</executable>

<compilerArgs>

<!-- 启用预览特性(如果需要) -->

<!-- <arg>--enable-preview</arg> -->

</compilerArgs>

<encoding>UTF-8</encoding>

</configuration>

</plugin>

</plugins>

</build>

属性方式配置

<properties>

<maven.compiler.source>17</maven.compiler.source>

<maven.compiler.target>17</maven.compiler.target>

<maven.compiler.compilerVersion>17</maven.compiler.compilerVersion>

<maven.compiler.fork>true</maven.compiler.fork>

<maven.compiler.executable>${JAVA_HOME}/bin/javac</maven.compiler.executable>

</properties>

<build>

<plugins>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-compiler-plugin</artifactId>

<version>3.11.0</version>

</plugin>

</plugins>

</build>

推荐使用第一种基本配置,除非你有特殊需求需要指定具体的JDK路径

相关推荐
上不如老下不如小3 分钟前
2025年第七届全国高校计算机能力挑战赛初赛 Java组 编程题汇总
java·计算机能力挑战赛
火白学安全12 分钟前
《Python红队攻防零基础脚本编写:进阶篇(一)》
开发语言·python·安全·web安全·网络安全·系统安全
泉城老铁19 分钟前
Springboot对接mqtt
java·spring boot·后端
FreeCode23 分钟前
LangGraph1.0智能体开发:运行时系统
python·langchain·agent
源码_V_saaskw23 分钟前
JAVA国际版同城跑腿源码快递代取帮买帮送同城服务源码支持Android+IOS+H5
android·java·ios·微信小程序
TT哇28 分钟前
消息推送机制——WebSocket
java·网络·websocket·网络协议
青瓷程序设计35 分钟前
植物识别系统【最新版】Python+TensorFlow+Vue3+Django+人工智能+深度学习+卷积神经网络算法
人工智能·python·深度学习
镜花水月linyi42 分钟前
ConcurrentHashMap 深入解析:从0到1彻底掌握(1.3万字)
java·后端
极客Bob42 分钟前
Java 集合操作完整清单(Java 8+ Stream API)
java
雨中飘荡的记忆43 分钟前
Javassist实战指南
java