挑选一个JDK牌子https://21doc.net/java/awesomejava#jvm-and-jdk,本文选用https://bell-sw.com/pages/downloads/,Liberica JDK支持比较多的平台和多个版本支持
下载JDK8、JDK11、JDK17
bellsoft-jdk8u333+2-linux-amd64-full.rpm
bellsoft-jdk11.0.15.1+2-linux-amd64.rpm
bellsoft-jdk17.0.3.1+2-linux-amd64.rpm
apache-maven-3.8.6-bin.zip
安装jdk和解压maven
rpm -ivh bellsoft-jdk8u333+2-linux-amd64-full.rpm
rpm -ivh bellsoft-jdk11.0.15.1+2-linux-amd64.rpm
rpm -ivh bellsoft-jdk17.0.3.1+2-linux-amd64.rpm
unzip apache-maven-3.8.6-bin.zip -d /usr/local/
安装后路径
/usr/lib/jvm/bellsoft-java8-full.x86_64
/usr/lib/jvm/bellsoft-java11.x86_64
/usr/lib/jvm/bellsoft-java17.x86_64
/usr/local/apache-maven-3.8.6
分别为jdk8、jdk11、jdk17的java程序增加别名java8、java11、java17
cp /usr/lib/jvm/bellsoft-java8-full.x86_64/bin/java /usr/lib/jvm/bellsoft-java8-full.x86_64/bin/java8
cp /usr/lib/jvm/bellsoft-java11.x86_64/bin/java /usr/lib/jvm/bellsoft-java11.x86_64/bin/java11
cp /usr/lib/jvm/bellsoft-java17.x86_64/bin/java /usr/lib/jvm/bellsoft-java17.x86_64/bin/java17
分别为jdk8、jdk11、jdk17版本创建对应的maven运行命令mvn8、mvn11、mvn17
cp /usr/local/apache-maven-3.8.6/bin/mvn /usr/local/apache-maven-3.8.6/bin/mvn8
cp /usr/local/apache-maven-3.8.6/bin/mvn /usr/local/apache-maven-3.8.6/bin/mvn11
cp /usr/local/apache-maven-3.8.6/bin/mvn /usr/local/apache-maven-3.8.6/bin/mvn17
分别修改mvn8、mvn11、mvn17文件,增加指定JAVA_HOME版本路径
/usr/local/apache-maven-3.8.6/bin/mvn8增加JDK8的JAVA_HOME
vi /usr/local/apache-maven-3.8.6/bin/mvn8
# 添加指定JDK8版本的JAVA_HOME
export JAVA_HOME=/usr/lib/jvm/bellsoft-java8-full.x86_64
/usr/local/apache-maven-3.8.6/bin/mvn11增加JDK11的JAVA_HOME
vi /usr/local/apache-maven-3.8.6/bin/mvn11
# 添加指定JDK11版本的JAVA_HOME
export JAVA_HOME=/usr/lib/jvm/bellsoft-java11.x86_64
/usr/local/apache-maven-3.8.6/bin/mvn17增加JDK17的JAVA_HOME
vi /usr/local/apache-maven-3.8.6/bin/mvn17
# 添加指定JDK17版本的JAVA_HOME
export JAVA_HOME=/usr/lib/jvm/bellsoft-java17.x86_64
配置环境变量
vi /etc/profile
# 在文件尾部增加
export JAVA_HOME8=/usr/lib/jvm/bellsoft-java8-full.x86_64
export JAVA_HOME=/usr/lib/jvm/bellsoft-java11.x86_64
export JAVA_HOME17=/usr/lib/jvm/bellsoft-java17.x86_64
export MAVEN_HOME=/usr/local/apache-maven-3.8.6
export PATH=$JAVA_HOME/bin:$JAVA_HOME8/bin:$JAVA_HOME17/bin:$MAVEN_HOME/bin:$PATH
jdk8/jdk11/jdk17运行
mvn8/mvn11/mvn17运行
创建一个简单的 Java 工程:
mvn archetype:generate -DgroupId=com.mycompany.example -DartifactId=Example -DinteractiveMode=false -DarchetypeCatalog=local
创 建一个 java 的 web 工程:
mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-webapp -DgroupId=com.mycompany.app -DartifactId=my-webapp
打包:
mvn package
编译:
mvn compile
编译测试程序:
mvn test-compile
清空:
mvn clean
运行测试:
mvn test
生成站点目录:
mvn site
生成站点目录并发布:
mvn site-deploy
安装当前工程的输出文件到本地仓库:
mvn install
安 装指定文件到本地仓库:
mvn install:install-file -DgroupId=<groupId> -DartifactId=<artifactId> -Dversion=1.0.0 -Dpackaging=jar -Dfile=<myfile.jar>
mvn install:install-file -DgroupId=jdk.tools -DartifactId=jdk.tools -Dpackaging=jar -Dversion=1.6 -Dfile=tools.jar -DgeneratePom=true
查看实际 pom 信息:
mvn help:effective-pom
分析项目的依赖信息:
mvn dependency:analyze
# 或
mvn dependency:tree
跳过测试运行 maven 任务:
mvn -Dmaven.test.skip=true XXX
生成 eclipse 项目文件:
mvn eclipse:eclipse -Dwtpversion=2.0
查看帮助信息:
mvn help:help
或
mvn help:help -Ddetail=true
查看插件的帮助信息:
mvn <plug-in>:help,
# 比如:
mvn dependency:help
# 或
mvn ant:help
输出依赖包到 lib 文件夹:
mvn dependency:copy-dependencies -DoutputDirectory=lib
下载源码
mvn dependency:sources
下载 API 文档:
mvn dependency:resolve -Dclassifier=javadoc
生成 doc 文档:
mvn javadoc:javadoc
maven 库搜索地址:
http://search.maven.org/
http://mvnrepository.com/
maven 仓库:
alimaven
aliyun maven
https://maven.aliyun.com/repository/public/
huaweicloud
huawei maven
https://mirrors.huaweicloud.com/repository/maven/
ibiblio
Human Readable Name for this Mirror.
http://mirrors.ibiblio.org/pub/mirrors/maven2/
jboss-public-repository-group
JBoss Public Repository Group
http://repository.jboss.org/nexus/content/groups/public
central
Maven Repository
https://repo.maven.apache.org/maven2