Home Java javaTutorial A complete guide to installing and configuring Maven on Mac systems

A complete guide to installing and configuring Maven on Mac systems

Jan 28, 2024 am 09:42 AM
Install maven mac system

A complete guide to installing and configuring Maven on Mac systems

Detailed explanation of the methods and techniques of installing Maven on Mac system

As a developer, installing Maven on Mac system is a very common requirement, because Maven is a very Popular build tool for managing dependencies and build processes of Java projects. This article will introduce in detail the methods and techniques of installing Maven on Mac system, and provide specific code examples.

1. Download Maven

First, you need to download the latest version of Maven from the official website (https://maven.apache.org/download.cgi). On the website, two versions can be found: binary and source. If you just want to use Maven without participating in Maven development, it is recommended to download the binary version. Click the link to download the binary version and select a suitable download image.

2. Install Maven

After the download is completed, find the download file, usually in .tar.gz or .zip format. Taking the .tar.gz format as an example, extract it to a suitable directory, such as the /opt directory. Open the terminal and enter the following command:

cd /opt
tar -zxvf apache-maven-3.6.3-bin.tar.gz

After decompression is completed, an apache-maven-3.6.3 folder will be generated in the directory /opt, which contains all Maven files. Next, we need to configure Maven into environment variables.

3. Configure environment variables

Open the terminal and enter the following command:

vim ~/.bash_profile

If there is no .bash_profile file, enter the following command to create the file:

touch ~/.bash_profile

Add the following content to the .bash_profile file:

export M2_HOME=/opt/apache-maven-3.6.3
export PATH=$PATH:$M2_HOME/bin

Save the file and exit edit mode. Enter the following command to make the modification effective:

source ~/.bash_profile

In this way, Maven is successfully configured into the environment variables.

4. Verify the installation

Open the terminal and enter the following command:

mvn -version

If the installation is successful, the following information will be displayed:

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /opt/apache-maven-3.6.3
Java version: 1.8.0_271, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_271.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "11.0.1", arch: "x86_64", family: "mac"

This means Maven installation Successful, and the Maven version information and Java related information are displayed.

5. Use Maven

After the installation is complete, you can use Maven to create, build and manage Java projects. Below is a simple example that demonstrates how to use Maven to create a Java project.

  1. Create project directory

First, create an empty directory as your project directory. Enter the following command in the terminal:

mkdir my-project
cd my-project
  1. Create project structure

Create the following structure in the project directory:

mkdir -p src/main/java
mkdir -p src/main/resources
mkdir -p src/test/java
mkdir -p src/test/resources
  1. Create Java class

Create a Java class in the src/main/java directory, such as HelloWorld.java. Enter the following command in the terminal:

cd src/main/java
touch HelloWorld.java

Use a text editor to open the HelloWorld.java file and add the following code:

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, Maven!");
    }
}

Save the file and exit the editor.

  1. Compile the project

Return to the project root directory and execute the following command to compile the project:

cd ../..
mvn compile
  1. Run the project

Execute the following command to run the project:

mvn exec:java -Dexec.mainClass="HelloWorld"

If everything goes well, you will see the output in the terminal: "Hello, Maven!".

6. Summary

Through the introduction of this article, you should have learned how to install Maven on a Mac system and use Maven to create and build Java projects. I hope this content will be helpful to you when using Maven in development. Happy programming!

The above is the detailed content of A complete guide to installing and configuring Maven on Mac systems. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1511
276
Detailed steps to install Go language on Win7 computer Detailed steps to install Go language on Win7 computer Mar 27, 2024 pm 02:00 PM

Detailed steps to install Go language on Win7 computer Go (also known as Golang) is an open source programming language developed by Google. It is simple, efficient and has excellent concurrency performance. It is suitable for the development of cloud services, network applications and back-end systems. . Installing the Go language on a Win7 computer allows you to quickly get started with the language and start writing Go programs. The following will introduce in detail the steps to install the Go language on a Win7 computer, and attach specific code examples. Step 1: Download the Go language installation package and visit the Go official website

How to install Go language under Win7 system? How to install Go language under Win7 system? Mar 27, 2024 pm 01:42 PM

Installing Go language under Win7 system is a relatively simple operation. Just follow the following steps to successfully install it. The following will introduce in detail how to install Go language under Win7 system. Step 1: Download the Go language installation package. First, open the Go language official website (https://golang.org/) and enter the download page. On the download page, select the installation package version compatible with Win7 system to download. Click the Download button and wait for the installation package to download. Step 2: Install Go language

Java Maven build tool advancement: optimizing compilation speed and dependency management Java Maven build tool advancement: optimizing compilation speed and dependency management Apr 17, 2024 pm 06:42 PM

Optimize Maven build tools: Optimize compilation speed: Take advantage of parallel compilation and incremental compilation. Optimize dependencies: Analyze dependency trees and use BOM (bill of materials) to manage transitive dependencies. Practical case: illustrate optimizing compilation speed and dependency management through examples.

How to download 360 Secure Browser on your computer How to download 360 Secure Browser on your computer Apr 12, 2024 pm 01:52 PM

How to download 360 Secure Browser on your computer? It is a very secure web browser software. This browser is very rich in functions and very simple to operate. Using 360 Secure Browser to browse the web can protect user privacy and security very well. Many people like to use this browser. Browser office, but many people still don’t know how to download and install 360 Secure Browser on their computers. This article will give you a detailed introduction to the installation process of the 360 ​​Safe Browser PC version, hoping to help you solve the problem. Overview of the installation process under the computer version of 360 Secure Browser 1. On the computer’s main page, find “360 Software Manager” and enter (as shown in the picture). 2. Open 360 Software Manager and find the search box (as shown in the picture). 3. Click Search

PHP FFmpeg extension installation guide: easy-to-follow tutorial PHP FFmpeg extension installation guide: easy-to-follow tutorial Mar 28, 2024 pm 02:17 PM

PHPFFmpeg Extension Installation Guide: Simple and easy-to-understand tutorial In the process of website development, sometimes we need to process various multimedia files, such as audio, video, etc. FFmpeg is a powerful multimedia processing tool that can process audio, video and other formats, and supports various transcoding, cutting and other operations. The PHPFFmpeg extension is an extension library that calls FFmpeg functions in PHP. It can be used to process multimedia files easily. Below we will introduce PHPF in detail

How to open Python after downloading How to open Python after downloading Apr 03, 2024 pm 05:12 PM

To open the Python you just downloaded, follow these steps: Place the installer in an easily accessible location. Double-click the installer icon and follow the on-screen instructions. Once the installation is complete, enter "python" in a command prompt or terminal window to start a Python interactive shell.

Comprehensive understanding of the Go install command: Installing and building Go programs Comprehensive understanding of the Go install command: Installing and building Go programs Apr 07, 2024 pm 04:54 PM

The Goinstall command is used to compile and install Go programs. It allows projects to be built and installed locally into the $GOPATH/bin directory. Options include: -v (verbose mode), -p (parallel build), -x (show running command), -target (set target operating system and architecture), which can be used to install dependencies and exclude tests.

Essential PHP programs: Install these to run smoothly! Essential PHP programs: Install these to run smoothly! Mar 27, 2024 pm 05:54 PM

Essential PHP programs: Install these to run smoothly! PHP is a popular server-side scripting language that is widely used to develop web applications. To successfully run a PHP program, you first need to install some necessary software and tools on the server. In this article, we will introduce the software and tools that must be installed, along with specific code examples to help you run PHP programs smoothly. 1. PHP interpreter The core of the PHP program is the PHP interpreter, which is responsible for parsing and executing PHP code. To install the PHP interpreter, you can follow

See all articles