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

相关推荐
红尘炼丹客2 分钟前
《DeepSeek-OCR: Contexts Optical Compression》速览
人工智能·python·自然语言处理·ocr
Dxxyyyy8 分钟前
零基础学JAVA--Day26(枚举类)
java·开发语言
☼←安于亥时→❦10 分钟前
Playwright 安装与使用
python·playwright
黑屋里的马20 分钟前
java的设计模式之桥接模式(Bridge)
java·算法·桥接模式
升鲜宝供应链及收银系统源代码服务23 分钟前
升鲜宝生鲜配送供应链管理系统---PMS--商品品牌多语言存储与 Redis 缓存同步实现
java·开发语言·数据库·redis·缓存·开源·供应链系统
大佬,救命!!!25 分钟前
python实现象棋
开发语言·python·学习笔记·pygame·少儿编程·记录成长
棉猴26 分钟前
《pygame中Sprite类实现多帧动画》注-通过多张序列帧显示动画2-2
开发语言·python·游戏·游戏程序·pygame
知兀29 分钟前
【Spring/SpringBoot】<dependencyManagement> + import 导入能继承父maven项目的所有依赖,类似parent
spring boot·spring·maven
练习时长一年34 分钟前
Spring AoP的切点匹配
java·开发语言