Hello Friends,
In this tutorial I will show you how to install and configure MAVEN in Ubuntu.
Maven is a Java tool for Project Management to make build process easier. I used the maven to compile and package my storm topology to run on storm cluster both in production mode and local mode.
Storm is a Apache framework for real time computation.
http://ashuuni123.blogspot.com/2013/08/installing-java-on-linuxubuntu.html
Installation of Maven on ubuntu can be pretty straightforward
$ mvn -version
Output should something like this-
* groupId –
* artifactId –
* version – The
The following lists gives an overview of the important Maven life cycle phases.
In this tutorial I will show you how to install and configure MAVEN in Ubuntu.
Maven is a Java tool for Project Management to make build process easier. I used the maven to compile and package my storm topology to run on storm cluster both in production mode and local mode.
Storm is a Apache framework for real time computation.
Prerequisites:
JAVA 1.5 or above. follow the following link to see how to install java and set environment for java.
http://ashuuni123.blogspot.com/2013/08/installing-java-on-linuxubuntu.html
Installation of Maven on ubuntu can be pretty straightforward
$ sudo apt-get install maven2
Files should be installed in /usr/share/maven2Verification
Type “mvn -version” to verify the installation.$ mvn -version
Output should something like this-
Apache Maven 2.2.1 (rdebian-8)
Java version: 1.7.0_25
Java home: /usr/local/jdk1.7.0_25/jre
Default locale: en_IN, platform encoding: UTF-8
OS name: "linux" version: "3.2.0-52-generic-pae" arch: "i386" Family: "unix
Java version: 1.7.0_25
Java home: /usr/local/jdk1.7.0_25/jre
Default locale: en_IN, platform encoding: UTF-8
OS name: "linux" version: "3.2.0-52-generic-pae" arch: "i386" Family: "unix
Where the Maven installed?
The Apt-get installation will install all the required files in the following folder structure-Default structure create by maven for a project
Sample of pom.xml file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org /2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>esc</groupId>
<artifactId>storm-experiment-2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerVersion>1.7</compilerVersion>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.path.to.main.Class</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<!-- Repository where we can found the storm dependencies -->
<repository>
<id>clojars.org</id>
<url>http://clojars.org/repo</url>
</repository>
</repositories>
<dependencies>
<!-- Storm Dependency -->
<dependency>
<groupId>storm</groupId>
<artifactId>storm</artifactId>
<version>0.8.2</version>
</dependency>
</dependencies>
</project>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>esc</groupId>
<artifactId>storm-experiment-2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerVersion>1.7</compilerVersion>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.path.to.main.Class</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<!-- Repository where we can found the storm dependencies -->
<repository>
<id>clojars.org</id>
<url>http://clojars.org/repo</url>
</repository>
</repositories>
<dependencies>
<!-- Storm Dependency -->
<dependency>
<groupId>storm</groupId>
<artifactId>storm</artifactId>
<version>0.8.2</version>
</dependency>
</dependencies>
</project>
* project – root element
* modelVersion –
The modelVersion
element sets what version of the POM model you are using
* groupId –
The groupId
element is a unique ID for an organization, or a project
* artifactId –
The artifactId
element contains the name of the project you are building
* version – The versionId
element contains the version number of the project.
The above
groupId
, artifactId
and version
elements would result in
a JAR file being built and put into the local Maven repository Maven life cycle
Every build follows a specified life cycle. Maven comes with a default life cycle that includes the most common build phases like compiling, testing and packaging.The following lists gives an overview of the important Maven life cycle phases.
- validate - checks if the project is correct and all information is available
- compile - compiles source code in binary artifacts
- test - executes the tests
- package - takes the compiled code and package it, for example into a JAR file.
- integration-test - takes the packaged result and executes additional tests, which require the packaging
- verify - performs checks if the package is valid
- install - install the result of the package phase into the local Maven repository
- deploy - deploys the package to a target, i.e. remote repository
Maven Repository
There
are 3 types of repository in maven
- Local Repository
- Remote Repository
- Central Repository
Local Repository: When you install and run maven first time, it will create a .m2 directory on your home directory, which contains a another directory name repository like-
$HOME/.m2/repository
This
the default location for the jar which maven check. If the particular
jar is not in local repository then it will be downloaded from the
remote repository which is set by maven when we installed the maven.
Remote Repository : which is developer's own custom repository containing required libraries or other project jars.
Central Repository : Maven central repository is repository provided by Maven community. It contains a large number of commonly used libraries.
When Maven does not find any dependency in local repository, it starts searching in central repository using following URL: http://repo1.maven.org/maven2/
Central Repository : Maven central repository is repository provided by Maven community. It contains a large number of commonly used libraries.
When Maven does not find any dependency in local repository, it starts searching in central repository using following URL: http://repo1.maven.org/maven2/
Using maven behind proxy
To use maven behind the proxy we have to define the proxy setting in setting.xml file inside the proxy element.
The setting file is found in /etc/maven2/setting.xml
Add
the following line under proxy element
<settings>
<proxies>
<proxy>
<active>true</active>
<protocol>http</protocol>
<host>192.168.1.100</host>
<port>3128</port>
<username>your-username</username>
<password>your-password</password>
</proxy>
</proxies>
</settings>
No comments:
Post a Comment