Mac environment configuration jdk, Maven

1. Install Java jdk

1. Check whether your mac is macOS x64 or macOS ARM64

Open the terminal and enter:
uname -a
Insert image description here
2. Go to the Oracle official website to download jdk (I downloaded the 1.8 version, project requirements).
There is a lock because you need to agree to the agreement and log in to the Oracle account. If not, it will be very fast to register. You will be logged in immediately. The download has started
Insert image description here
. Just install it directly after downloading. It will be OK in a few clicks.

3. Check the jdk installation path:

java -version1) After downloading and installing jdk, the java version can be viewed on the terminal command line , but the JAVA_HOME environment variable will not be automatically set
Insert image description here
. 2) Terminal input:/usr/libexec/java_home -V
Insert image description here

/Library/Java/JavaVirtualMachines/jdk-1.8.jdk/Contents/Home

That is the installation path of jdk

4. Configure JDK environment variables.
Enter the following command to create a new script file: touch .bash_profile
Open the above file, open -e .bash_profile
Insert image description here
enter ⬇️ and save: Replace the first line JAVA_HOME with your own jdk path.

JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-1.8.jdk/Contents/Home
PATH=$JAVA_HOME/bin:$PATH:.
CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.
export JAVA_HOME
export PATH
export CLASSPATH

Insert image description here
Enter ⬇️ to make the configuration just written take effect.

source .bash_profile

5. Check whether the jdk is installed successfully and whether the system can recognize the java command: ⬇️
Insert image description here
IDEA adds the jdk path. After searching for a long time, I can’t find the file row on IDEA. It turns out that the Mac ones are in the top corner of the window. . . Mac Xiaobai vomited blood. . .
Insert image description here

OK!

2. Maven installation and environment configuration

1. Go to the Maven official website to download , select the Maven version corresponding to the jdk version just downloaded above , and install the compiled binary version. Specifically, install zip or tar.gz. The novice tutorial I read said that it is to install tar.gz on Mac.
Insert image description here
2. Unzip the installed Maven file and copy it to:

/usr/local/apache-maven-3.9.4

Insert image description here
3. Open the script file created when configuring jdk in the terminal: open -e .bash_profile
input: ⬇️

MAVEN_HOME=/usr/local/apache-maven-3.9.4
PATH=${
    
    PATH}:${MAVEN_HOME}/bin:${JAVA_HOME}/bin

Insert image description here
Enter ⬇️ to make the configuration just written take effect.

source .bash_profile

4. Check whether maven is installed successfully and whether the system can recognize the maven/mvn command: ⬇️
Insert image description here

Encountered a problem :
Then I found that my maven command still didn't work and was not recognized. I searched for tutorials and found a way
Insert image description here
Insert image description here
to solve the problem!
Insert image description here
At this point, the environment configuration of my Mac system jdk and Maven is completed!

3. Maven configuration

I thought the configuration was over, but it was far from enough. . . . . . Refer to Tutorial
1. Generate the .m2 folder.
Terminal execution: mvn help:system
Insert image description here
Only then will the Maven local warehouse and other things be generated. The .m2 folder can be found in the user directory.
Insert image description here

Insert image description here
2. Configure the user-wide settings.xml file.
Just follow the configuration given by the company's seniors. It turns out that pom.xml will be automatically parsed to the local warehouse.
选中maven项目文件夹,右键用IDEA打开。打开pom文件,自动下载依赖至本地仓库,pom文件右上角显示绿色;本地仓库路径下可看到已下载的依赖包
Intranet java IDEA maven development environment configuration

3, idea maven placement
Insert image description here

Reference articles:
Mac Configuring JDK environment variables
Mac environment variables, maven3.1.1 and jdk1.7.0.45 Configuring
Maven Environment configuration
mac After installing maven, encounter the problem of zsh: command not found: mvn
Maven installation and configuration
intranet java IDEA maven development environment configuration

Guess you like

Origin blog.csdn.net/weixin_42416791/article/details/132490541