Maven is a popular project management tool that helps developers manage project construction, reporting and documentation software project management tools.
Installing Maven in a CentOS system is a relatively simple process, just follow the steps below.
Preparation
Before you start installing, you need to make sure your CentOS system has Java installed, because Maven is Java-based.
You can runjava -version
Command to check if Java is installed. If not installed, you need to install Java first.
In addition, you will also need to make sure your system has an Internet connection in order to download the Maven installation package from Maven's official website.
Download and install Maven
First, visit (Maven's official website) and download the latest version of Maven installation package. You can choose to download the compressed package in the format.
usewget
Command or download the Maven installation package directly from the browser to your CentOS system.
For example, if you are using the wget command, you can run the following command to download the Maven installation package:
wget /maven/maven-3/3.8.4/binaries/apache-maven-3.8.
After the download is completed, usetar
Command to unzip the Maven installation package to the specified directory.
For example, you can unzip Maven to/opt
In the directory:
sudo tar -xvzf apache-maven-3.8. -C /opt
After decompression is complete, you need to set environment variables so that you can use the Maven command anywhere.
You can edit/etc/profile
File to set environment variables.
Open with a text editor/etc/profile
File, and add the following at the end of the file:
export M2_HOME=/opt/apache-maven-3.8.4 export PATH=$PATH:$M2_HOME/bin
Save and close/etc/profile
document. Then, runsource /etc/profile
Command to make environment variables take effect.
runmvn -version
Command to verify that Maven has been installed successfully. If everything works fine, you should be able to see the version information of Maven.
Frequently Asked Questions and Solutions
You may encounter some problems during the installation of Maven.
Here are some common problems and their solutions:
-
Java not installed: If the system prompts that Java is not installed, you need to install Java first. You can use
yum install java-1.8.0-openjdk
Command to install OpenJDK. -
Environment variable setting error: If you are running
mvn
I received an error of "Command Not Found" when I was commanded, which may be because the environment variable is not set correctly. Check, please/etc/profile
Set environment variables in the file and make sureM2_HOME
The variable points to the correct Maven installation directory. - Slow download speed: If you encounter slow downloading speed when downloading the installation package from the official Maven website, you can try using a domestic mirror site to download the Maven installation package.
Practical application cases
Now, you have successfully installed Maven in CentOS. As a practical application case, you can try to build a Java project using Maven.
Here are one simple step:
- Create a new Java project directory and create a new Java project name under that directory
Maven project file. You can use a text editor to edit this file and add some basic Maven configuration.
- exist
In the file, you can define project dependencies, build plugins, and other configurations. For example, you can add a JUnit dependency to add unit test support to your project.
- save
After the file, you can run it
mvn package
Commands to build your project. Maven will automatically download the dependencies required by the project and compile and package your project. - After the build is completed, you can
target
Find the generated JAR file or WAR file in the directory. You can use this file to deploy your application to the server.
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.