1. Confirm whether the Java development environment-JDK is installed
-
Open Terminal and enter:
java -version
macdeMacBook-Pro:test-java mac$ java -version java version "13-ea" 2019-09-17 Java(TM) SE Runtime Environment (build 13-ea+33) Java HotSpot(TM) 64-Bit Server VM (build 13-ea+33, mixed mode, sharing)
-
If the java version number is returned, it means it has been installed
-
Otherwise, install jdk first: configure Java development environment on Mac
2. Download and install eclipse
-
download:
-
Enter eclipse's official website http://www.eclipse.org/home/index.php
-
Click "Download" in the upper right corner of the page
-
Click "Download 64 bit" in the middle of the page
-
Click "Download" to download
-
-
installation:
-
Double-click the "eclipse-inst-mac64.dmg" file downloaded in the previous step
-
Double-click the icon
-
There are a variety of download and installation packages listed here, and you can choose according to your needs. For example, I chose "Eclipse IDE for Java Developers":
-
Click "INSTALL" to download and install. (If there is a problem in the process, click the menu item with a yellow exclamation mark in the upper right corner, and select "UPDATE" to update before proceeding)
-
After the installation is complete, find the eclipse icon according to the installation path ""/Users/mac/eclipse/java-2019-12" and double-click to open it. (For ease of use, you can move to "/Applications". Find and view eclipse in Launchpad)
-
3. Configure JDK for eclipse
-
Click the above eclipse icon, then click "Launch" (just follow the default workspace), and then enter the eclipse preferences:
-
Select "Installed JREs" under "java" from the left sidebar, then click the "Add" button, select "Standard VM" in the pop-up box and click the "Next" button:
-
In the Add JRE interface, click the "Directory" button behind "JRE home" and select the Home folder path when JDK is installed. For example, mine is "/Library/Java/JavaVirtualMachines/jdk-13.jdk/Contents/Home". As for "JRE name", the default is "Home", and then click "finish" (if it has been configured, it will display "The JRE name is already in use.")
-
Then check the JRE you just added, and then click "Apply and Close".
4. Run a simple example
-
Click "Creat a new Java project"
-
Enter "Project name", such as "softTest1"; JRE selects the third item "use default JRE (currently "Home")", which is the default JRE configured for eclipse above; other defaults are fine; finally click "finish" to create the project
-
Then click "Create" directly in the pop-up box
-
Create a package:
-
Right-click the project name softTest1->new->Package
-
The package name in the pop-up box can be defaulted or modified
-
-
Create class:
-
Right-click the newly created package name softTest1->new->class
-
The "Name" in the pop-up box can be named "HelloWorld", other defaults are fine, click "finish".
-
-
Write the code, click run, you can see the output in the console
Reference link: