Home > Maven, Ubuntu > Getting started with Maven on Ubuntu

Getting started with Maven on Ubuntu

Maven is a project management tool. Installing it in Ubuntu is very straightforward. Run the following command in the terminal to install Maven.

sudo apt-get install maven2

To create a simple project using maven use this command

mvn archetype:generate

and when prompted enter option “15”. This creates a quickstart project. Read more about this command here.
Set a MAVEN_REPO environment variable by adding this line in the .profile file in the home folder
export MAVEN_REPO=/home/<user>/.m2/repository ; Replace the user with the user-name on Ubuntu.
This variable will be used by Eclipse.
In the project created earlier, run this command

mvn clean install

This will clean, build and install your project. Note: this command has to be run in the dir of the project that contains the pom.xml file. The jar file created from the build can be found in the target directory.
Here is the directory structure after the build:(The following values were used to create the project by using the archetype plugin — groupId: test;artifactId: test;version: 1.0-SNAPSHOT;package: com.codesilo.test)

test
|– pom.xml
|– src
|   |– main
|   |   `– java
|   |       `– com
|   |           `– codesilo
|   |               `– test
|   |                   `– App.java
|   `– test
|       `– java
|           `– com
|               `– codesilo
|                   `– test
|                       `– AppTest.java
`– target
|– classes
|   `– com
|       `– codesilo
|           `– test
|               `– App.class
|– maven-archiver
|   `– pom.properties
|– surefire-reports
|   |– TEST-com.codesilo.test.AppTest.xml
|   `– com.codesilo.test.AppTest.txt
|– test-1.0-SNAPSHOT.jar
`– test-classes
`– com
`– codesilo
`– test
`– AppTest.class

Read more about build lifecycle here.

Technorati Tags: , , , , , , , ,

Advertisements
Categories: Maven, Ubuntu
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: