前言
跟前端篇一樣,現在記錄一下後臺應用端開發環境的搭建,針對的是java環境,現在分享給大家。
操作
1、下載和安裝Java
下載地址
JDK19和17
JDK8和11
下載dmg安裝即可,接著查詢安裝java的位置
➜ ~ /usr/libexec/java_home -V
Matching Java Virtual Machines (1):
19.0.2 (arm64) "Oracle Corporation" - "Java SE 19.0.2" /Library/Java/JavaVirtualMachines/jdk-19.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk-19.jdk/Contents/Home
找到java安裝位置 之後,現在我們來編輯.bash_profile檔案
,新增java環境
#java home
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-19.jdk/Contents/Home
export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.
儲存完之後,別忘了source ~/.bash_profile
2、下載和安裝Maven
點選官網下載地址下載
下載之後解壓到你想要儲存的地方即可。
儲存完之後,配置一下環境變數,再次編輯~/.bash_profile
#java home
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-19.jdk/Contents/Home
export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.
# maven home
M3_HOME=/Users/justinzhang/Library/Maven/apache-maven-3.9.0
export PATH=$JAVA_HOME/bin:$M3_HOME/bin:$PATH:
這樣就完成了Java和Maven的安裝,檢視Java和Maven的版本
➜ ~ java --version
java 19.0.2 2023-01-17
Java(TM) SE Runtime Environment (build 19.0.2+7-44)
Java HotSpot(TM) 64-Bit Server VM (build 19.0.2+7-44, mixed mode, sharing)
➜ ~ mvn -v
Apache Maven 3.9.0 (9b58d2bad23a66be161c4664ef21ce219c2c8584)
Maven home: /Users/justinzhang/Library/Maven/apache-maven-3.9.0
Java version: 19.0.2, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-19.jdk/Contents/Home
Default locale: zh_CN_#Hans, platform encoding: UTF-8
OS name: "mac os x", version: "13.2.1", arch: "aarch64", family: "mac"
3、配置maven setting.xml檔案
先找到maven安裝路徑,我的路徑是
~/Library/apache-maven-3.5.0/conf/settings.xml
找到之後編輯setting.xml檔案
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<mirror>
<id>mirror</id>
<mirrorOf>central,jcenter,!rdc-releases,!rdc-snapshots</mirrorOf>
<name>mirror</name>
<url>https://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
</mirrors>
<servers>
<server>
<id>rdc-releases</id>
<username>xxx</username>
<password>xxx(H</password>
</server>
<server>
<id>rdc-snapshots</id>
<username>xxx</username>
<password>xxx(H</password>
</server>
</servers>
<profiles>
<profile>
<id>rdc</id>
<properties>
<altReleaseDeploymentRepository>
rdc-releases::default::https://packages.aliyun.com/maven/repository/2113702-release-6l40oS/
</altReleaseDeploymentRepository>
<altSnapshotDeploymentRepository>
rdc-snapshots::default::https://packages.aliyun.com/maven/repository/2113702-snapshot-zW0Kdb/
</altSnapshotDeploymentRepository>
</properties>
<repositories>
<repository>
<id>central</id>
<url>https://maven.aliyun.com/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>snapshots</id>
<url>https://maven.aliyun.com/nexus/content/groups/public</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>rdc-releases</id>
<url>https://packages.aliyun.com/maven/repository/2113702-release-6l40oS/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>rdc-snapshots</id>
<url>https://packages.aliyun.com/maven/repository/2113702-snapshot-zW0Kdb/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>https://maven.aliyun.com/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>snapshots</id>
<url>https://maven.aliyun.com/nexus/content/groups/public</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>rdc-releases</id>
<url>https://packages.aliyun.com/maven/repository/2113702-release-6l40oS/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>rdc-snapshots</id>
<url>https://packages.aliyun.com/maven/repository/2113702-snapshot-zW0Kdb/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>rdc</activeProfile>
</activeProfiles>
</settings>
這樣就配置好了Maven。
Idea配置
現在我們到idea中配置Java和Maven環境
總結
1、如果你使用的是壓縮包安裝方式安裝Java,只要放到指定目錄即可,然後配置Java環境,而使用dmg安裝方式安裝後的Java目錄,必須使用/usr/libexec/java_home -V
才能獲取取。
2、安裝好maven之後記得配置setting.xml檔案。
3、Idea如果報Java相關錯,看看是不是沒有設定java版本
引用
lombok與jdk版本對應關係 - 愛碼網
解決 Maven ‘parent.relativePath‘ of POM
MacOS下安裝及配置Maven
超詳細的Java安裝教程(Mac 版)