May 26, 2021 Maven
1. Maven - Environment configuration
3. Step 1: Check the Java installation
4. Step 2: Set up the Java environment
5. Step 3: Download the Maven file
6. Step 4: Unzim the Maven file
7. Step 5: Set the Maven environment variable
Maven is a Java-based tool, so the first thing to do is install the JDK.
Project | Requirements |
---|---|
Jdk |
Maven 3.3 requires JDK 1.7 or more
Maven 3.2 requires JDK 1.6 or more Maven 3.0/3.1 requires JDK 1.5 or more |
Memory | There are no minimum requirements |
Disk | Maven's own installation requires approximately 10 MB of space. I n addition, the extra disk space will be used for your local Maven repository. The size of your local warehouse depends on usage, but is expected to be at least 500 MB |
Operating system | There are no minimum requirements |
Now open the console and execute the
java
Operating system | Task | Command |
---|---|---|
Windows | Open the command console |
c:\> java -version
|
Linux | Open the command terminal |
$ java -version
|
Mac | Open the terminal |
machine:~ joseph$ java -version
|
Let's verify the output on all platforms:
Operating system | Output |
---|---|
Windows |
java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b07) Java HotSpot(TM) Client VM (build 17.0-b17, mixed mode, sharing) |
Linux |
java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b07) Java HotSpot(TM) Client VM (build 17.0-b17, mixed mode, sharing) |
Mac |
java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b07) Java HotSpot(TM)64-Bit Server VM (build 17.0-b17, mixed mode, sharing) |
If you don't have Java installed, install the Java Software Development Kit (SDK) from the following url: http://www.oracle.com/technetwork/java/javase/downloads/index.html. Let's assume that you have installed a version of Java that is 1.6.0-21.
Set
JAVA_HOME
variables and point to the Java installation directory on your machine.
For example:
Operating system | Output |
---|---|
Windows |
Set the environment variable JAVA_HOME to
C:\Program Files\Java\jdk1.6.0_21 |
Linux |
export JAVA_HOME=/usr/local/java-current
|
Mac |
export JAVA_HOME=/Library/Java/Home
|
Add the Java compiler address to the system path.
Operating system | Output |
---|---|
Windows | put the string"; C:\Program Files/Java jdk1.6.0_21 "" |
Linux | export PATH=$PATH:$JAVA_HOME/bin/ |
Mac | not required |
Use the java-version command mentioned above to verify the Java installation.
Download Maven 3.2.5: http://maven.apache.org/download.html
Unzim the file to the location you want to install Maven 3.2.5 and you will get the apache-maven-3.2.5 subdirectory.
Operating system | Location (depending on your installation location) |
---|---|
Windows |
C:\Program Files\Apache Software Foundation\apache-maven-3.2.5
|
Linux |
/usr/local/apache-maven
|
Mac |
/usr/local/apache-maven
|
Add M2_HOME, M2, MAVEN_OPTS to the environment variable.
Operating system | Output |
---|---|
Windows |
Use system properties to set environment variables.
M2_HOME=C:\Program Files\Apache Software Foundation\apache-maven-3.2.5 M2=%M2_HOME%\bin MAVEN_OPTS=-Xms256m -Xmx512m |
Linux |
Open the command terminal to set the environment variable.
export M2_HOME=/usr/local/apache-maven/apache-maven-3.2.5 export M2=$M2_HOME/bin export MAVEN_OPTS=-Xms256m -Xmx512m |
Mac |
Open the command terminal to set the environment variable.
export M2_HOME=/usr/local/apache-maven/apache-maven-3.2.5 export M2=$M2_HOME/bin export MAVEN_OPTS=-Xms256m -Xmx512m |
Now add the M2 variable to the system "Path" variable
Operating system | Output |
---|---|
Windows | Add the string "; %M2%" to the end of the system "Path" variable |
Linux | export PATH=$M2:$PATH |
Mac | export PATH=$M2:$PATH |
Now open the console and execute the following mvn command.
Operating system | Output | Command |
---|---|---|
Windows | Open the command console |
c:\> mvn --version
|
Linux | Open the command terminal |
$ mvn --version
|
Mac | Open the terminal |
machine:~ joseph$ mvn --version
|
Finally, verifying the output of the above command should look like this:
Operating system | Output |
---|---|
Windows |
Apache Maven 3.2.5 (r801777;
2009-08-07 00:46:01+0530)
Java version: 1.6.0_21 Java home: C:\Program Files\Java\jdk1.6.0_21\jre |
Linux |
Apache Maven 3.2.5 (r801777;
2009-08-07 00:46:01+0530)
Java version: 1.6.0_21 Java home: C:\Program Files\Java\jdk1.6.0_21\jre |
Mac |
Apache Maven 3.2.5 (r801777;
2009-08-07 00:46:01+0530)
Java version: 1.6.0_21 Java home: C:\Program Files\Java\jdk1.6.0_21\jre |
Congratulations! Now that you've done all the setup, get started with Apache Maven.