Set up Java development environment in Macbook with Java 19 and Maven
3 min readDec 23, 2022
Tools
We gonna need following tools for Java development in Mac:
- Java SDK
- Maven
- Intelij Idea
Install Java 19 SDK
Download jdk-19 from Oracle website: https://www.oracle.com/java/technologies/downloads/#jdk19-mac.
For Apple M1 chip, you can download following installation package: https://download.oracle.com/java/19/latest/jdk-19_macos-aarch64_bin.dmg.
Once installation is successful, try ‘java -version’ in terminal, and you would be able to see Java information:
Install Maven for dependency management
- First download the maven package: https://dlcdn.apache.org/maven/maven-3/3.8.6/binaries/apache-maven-3.8.6-bin.tar.gz.
- Put the above tar.gz package into some folder you want. Then run following command to unzip it:
tar xzvf apache-maven-3.8.6-bin.tar.gz
- Then add the
bin
directory of the created directoryapache-maven-3.8.6
to thePATH
environment variable by using following command. Don’t forget to update the path to the correct path in the command.
export PATH=/SOME_PATH_TO_MAVEN/apache-maven-3.8.6/bin:$PATH
- You can put the above command in either ~/.bashrc for bash shell or ~/.zhrc for zsh shell, so that the PATH will get updated automatically every time you login to the system.
- Then run ‘mvn -v’ in the terminal, you would be able to see the mvn information:
Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
Maven home: /SOME_PATH_TO_MAVEN/apache-maven-3.8.6
Java version: 19.0.1, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-19.jdk/Contents/Home
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "11.6", arch: "aarch64", family: "mac"
Get sample Java project with Spring Boot
- You can get sample Java project by using https://start.spring.io/
- For more details about Spring Boot, please refer to: https://medium.com/@databackendtech/using-spring-boot-framework-for-java-application-9ba548f80eb3
Install Intelij Idea as the Java IDE
- The Intelij Idea can be downloaded here: https://www.jetbrains.com/idea/download/#section=mac
- After installing and opening Intelij Idea successfully, import the demo project we downloaded from https://start.spring.io/.
- Intelij Idea will prompt to find the java sdk, choose the Java 19 sdk that we installed in previous step.
- Open the Maven window and click ‘refresh’ button, so that Intelij Idea will download all dependencies mentioned in pom.xml
- Then we can click the ‘run’ button, the DemoApplication will be built and run
- console output would be like:
Summary
In this article, we explained how to set up Java development environment in Mac. Happy coding!