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

相关推荐
AI小怪兽2 小时前
基于YOLOv13的汽车零件分割系统(Python源码+数据集+Pyside6界面)
开发语言·python·yolo·无人机
wszy18092 小时前
新文章标签:让用户一眼发现最新内容
java·python·harmonyos
Eric.Lee20212 小时前
python实现 mp4转gif文件
开发语言·python·手势识别·手势交互·手势建模·xr混合现实
EntyIU2 小时前
python开发中虚拟环境配置
开发语言·python
wszy18092 小时前
顶部标题栏的设计与实现:让用户知道自己在哪
java·python·react native·harmonyos
kaizq3 小时前
AI-MCP-SQLite-SSE本地服务及CherryStudio便捷应用
python·sqlite·llm·sse·mcp·cherry studio·fastmcp
程序员小假3 小时前
我们来说一下无锁队列 Disruptor 的原理
java·后端
资生算法程序员_畅想家_剑魔3 小时前
Kotlin常见技术分享-02-相对于Java 的核心优势-协程
java·开发语言·kotlin
ProgramHan3 小时前
Spring Boot 3.2 新特性:虚拟线程的落地实践
java·jvm·spring boot
nbsaas-boot4 小时前
Go vs Java 的三阶段切换路线图
java·开发语言·golang