Linux build and install Maven environment

1. Preconditions:

1) Download and install JDK. Enter the command "java -version" at the terminal. If a message similar to the following appears, the JDK installation is successful.

$ java -version

java version "1.7.0_45"
OpenJDK Runtime Environment (rhel-2.4.3.3.el6-x86_64 u45-b15)
OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode)

2) Download Eclipse. It is recommended to download the latest JAVA development version (mine is LUNA). This automatically integrates the Maven plugin.

2. Start configuring maven:

1) Download Maven 3.2.3: http://maven.apache.org/download.cgi

2) Unzip apache-maven-3.2.3-bin.tar.gz, assuming the unzip path is: /sandbox/my_maven/apache-maven-3.2.3.

3) Set environment variables:

// Set the MAVEN_HOME system variable   
$ export M2_HOME= " /sandbox/my_maven/apache-maven-3.2.3 "   
// Add MAVEN_HOME\bin to the environment variable   
$ export PATH=$PATH:$M2_HOME/ bin  
 // Verify whether to save   
$ echo $M2_HOME  
 // Verify whether the environment variable is set successfully   
$ mvn - v   
 // If a series of information appears, the environment variable is set successfully  

Note: Since we are using export, the configured environment variables only work under the current shell, so do not turn off the current terminal in the middle, otherwise you need to reconfigure.

If you want to configure permanent environment variables, you can modify /etc/profile or .bash_profile in the user directory. The former works on all users, the latter works only on the user himself.

3. Create a maven repository:

1) Create a folder, assuming the path is: /sandbox/my_maven/maven_repository.

2) Open the /sandbox/my_maven/apache-maven-3.2.3/conf/setting.xml file and set our warehouse path:

<!-- localRepository  
  | The path to the local repository maven will use to store artifacts.  
  |  
  | Default: ${user.home}/.m2/repository  
 <localRepository>/path/to/local/repo</localRepository>  
 -->  
 <localRepository>/sandbox/my_maven/maven_repository</localRepository>

3) Run the command in the terminal to download the commonly used packages from the maven central repository to the local:

$ mvn help:system

4) If there is no error, open /sandbox/my_maven/maven_repository and you will find many more files.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324887624&siteId=291194637