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 小时前
Maven多模块项目MyMetaObjectHandler自动填充日期未生效
spring·maven·mybatis
harmful_sheep3 小时前
maven mvn 安装自定义 jar 包
java·maven·jar
李贺梖梖3 小时前
Maven初识
maven
007php0073 小时前
某大厂跳动面试:计算机网络相关问题解析与总结
java·开发语言·学习·计算机网络·mysql·面试·职场和发展
倔强青铜三3 小时前
苦练Python第63天:零基础玩转TOML配置读写,tomllib模块实战
人工智能·python·面试
JH30734 小时前
第七篇:Buffer Pool 与 InnoDB 其他组件的协作
java·数据库·mysql·oracle
浔川python社4 小时前
《网络爬虫技术规范与应用指南系列》(xc—3):合规实操与场景落地
python
B站计算机毕业设计之家4 小时前
智慧交通项目:Python+YOLOv8 实时交通标志系统 深度学习实战(TT100K+PySide6 源码+文档)✅
人工智能·python·深度学习·yolo·计算机视觉·智慧交通·交通标志
IT森林里的程序猿4 小时前
基于机器学习方法的网球比赛胜负趋势预测
python·机器学习·django