Maven is an Apache product which is a software project management and comprehension tool. This is based on the concept of a project object model. Which is known as (POM).Maven can manage a project's build, reporting and documentation from a central piece of information.
Building a Project with Maven:
--Download Maven : http://maven.apache.org/download.html
--Configure Maven :
1. Should inherit from a company-wide parent pom.xml.
2. Specify user in ${user.home}/.m2/settings.xml. Follow : Click Here
3. Configure a proxy to use for some or all of your HTTP requests in Maven 2.0. The username and password are only required if your proxy requires basic authentication. For more Information : Click Here
--Check whether it is installed by,
mvn --version
--To create a project in MVN,
mvn archetype:create \
-DarchetypeGroupId=org.apache.maven.archetypes \
-DgroupId=com.mycompany.app \
-DartifactId=my-app
--If the project is already built in MVN, go to the project location and, build it by the following command:
mvn package or
mvn clean install
--If you get Errors :
- [INFO] Failed to resolve artifact.
Missing:
----------
1) jnuit:junit:jar:3.8.1
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=jnuit -DartifactId=junit \
-Dversion=3.8.1 -Dpackaging=jar -Dfile=/path/to/file
Path to dependency:
1) org.apache.maven:maven:pom:2.1-SNAPSHOT
2) jnuit:junit:jar:3.8.1
----------
1 required artifact is missing.
for artifact:
org.apache.maven:maven:pom:2.1-SNAPSHOT
from the specified remote repositories:
central (http://repo1.maven.org/maven2)
This can be happened due to missing dependencies. This can be resolved by adding the dependencies by knowing exactly the what dependency and why it is missing.
This may be due to a missing jar file of a particular build or any other library jar files. E.g., Because of some older Sun JAR files.
--To compile Source using MVN,
mvn compile
If it is successfully compiled, Will get a message as, [INFO] BUILD SUCCESSFUL
--To Run Unit test,
mvn test
--To Compile test sources,
mvn test-compile
--To create a jar and install it in a local repository,
mvn package
--To skip the tests and run the project,
mvn install -DskipTests
or
mvn install -Dmaven.test.skip=true
The POM
Core of a project's configuration in Maven. A single configuration file that contains the majority of information required to build a project
* project This is the top-level element in all Maven pom.xml files.
* modelVersion This element indicates what version of the object model this POM is using. The version of the model itself changes very infrequently but it is mandatory in order to ensure stability of use if and when the Maven developers deem it necessary to change the model.
* groupId This element indicates the unique identifier of the organization or group that created the project. The groupId is one of the key identifiers of a project and is typically based on the fully qualified domain name of your organization. For example org.apache.maven.plugins is the designated groupId for all Maven plug-ins.
* artifactId This element indicates the unique base name of the primary artifact being generated by this project. The primary artifact for a project is typically a JAR file. Secondary artifacts like source bundles also use the artifactId as part of their final name. A typical artifact produced by Maven would have the form
* packaging This element indicates the package type to be used by this artifact (e.g. JAR, WAR, EAR, etc.). This not only means if the artifact produced is JAR, WAR, or EAR but can also indicate a specific lifecycle to use as part of the build process. (The lifecycle is a topic we will deal with further on in the guide. For now, just keep in mind that the indicated packaging of a project can play a part in customizing the build lifecycle.) The default value for the packaging element is JAR so you do not have to specify this for most projects.
* version This element indicates the version of the artifact generated by the project. Maven goes a long way to help you with version management and you will often see the SNAPSHOT designator in a version, which indicates that a project is in a state of development. We will discuss the use of snapshots and how they work further on in this guide.
* name This element indicates the display name used for the project. This is often used in Maven's generated documentation.
* url This element indicates where the project's site can be found. This is often used in Maven's generated documentation.
* description This element provides a basic description of your project. This is often used in Maven's generated documentation.
Maven Phases
Common Maven phases :
E.g., Just have to type as mvn clean, mvn test
* validate: validate the project is correct and all necessary information is available
* compile: compile the source code of the project
* test: test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
* package: take the compiled code and package it in its distributable format, such as a JAR.
* integration-test: process and deploy the package if necessary into an environment where integration tests can be run
* verify: run any checks to verify the package is valid and meets quality criteria
* install: install the package into the local repository, for use as a dependency in other projects locally
* deploy: done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.
There are two other Maven lifecycles of note beyond the default list above. They are
* clean: cleans up artifacts created by prior builds
* site: generates site documentation for this project
--To clean the project, copy dependencies, and package the project (executing all phases up to package), use the following command :
mvn clean dependency:copy-dependencies package
No comments:
Post a Comment