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路径

相关推荐
巧妹儿6 分钟前
Python 配置管理封神技:pydantic_settings+@lru_cache,支持优先级,安全又高效,杜绝重复加载!
开发语言·python·ai·配置管理
独隅10 分钟前
Python AI 全面使用指南:从数据基石到智能决策
开发语言·人工智能·python
胡耀超14 分钟前
Web Crawling 网络爬虫全景:技术体系、反爬对抗与全链路成本分析
前端·爬虫·python·网络爬虫·数据采集·逆向工程·反爬虫
小陈的进阶之路18 分钟前
Selenium元素定位
python·selenium
李昊哲小课18 分钟前
matplotlib多子图与复杂布局实战
python·数据分析·matplotlib·数据可视化
2401_8319207418 分钟前
持续集成/持续部署(CI/CD) for Python
jvm·数据库·python
写代码的【黑咖啡】24 分钟前
Python Web 开发新宠:FastAPI 全面指南
前端·python·fastapi
蝎子莱莱爱打怪25 分钟前
别再裸用 Claude Code 了!32 个亲测Skills + 8 个 MCP,开发效率直接拉满!
java·后端·claude
吴佳浩 Alben26 分钟前
GPU 编号错乱踩坑指南:PyTorch cuda 编号与 nvidia-smi 不一致
人工智能·pytorch·python·深度学习·神经网络·语言模型·自然语言处理
野犬寒鸦39 分钟前
JVM垃圾回收机制面试常问问题及详解
java·服务器·开发语言·jvm·后端·算法·面试