Maven’s Objectives
Maven’s primary goal is to allow a developer to comprehend the complete state of a development effort in the shortest period of time. In order to attain this goal there are several areas of concern that Maven attempts to deal with:
Providing a uniform build systemMaven allows a project to build using its project object model (POM) and a set of plugins that are shared by all projects using Maven, providing a uniform build system. Once you familiarize yourself with how one Maven project builds you automatically know how all Maven projects build saving you immense amounts of time when trying to navigate many projects.
Providing quality project informationMaven provides plenty of useful project information that is in part taken from your POM and in part generated from your project’s sources. For example, Maven can provide:
Other products can also provide Maven plugins to allow their set of project information alongside some of the standard information given by Maven, all still based on the POM.
Providing guidelines for best practices developmentMaven aims to gather current principles for best practices development, and make it easy to guide a project in that direction.
For example, specification, execution, and reporting of unit tests are part of the normal build cycle using Maven. Current unit testing best practices were used as guidelines:
Maven also suggests some guidelines on how to layout your project’s directory structure so that once you learn the layout you can easily navigate any other project that uses Maven and the same defaults.
Allowing transparent migration to new featuresMaven provides an easy way for Maven clients to update their installations so that they can take advantage of any changes that been made to Maven itself.
Installation of new or updated plugins from third parties or Maven itself has been made trivial for this reason.
- Making the build process easy
- Providing a uniform build system
- Providing quality project information
- Providing guidelines for best practices development
- Allowing transparent migration to new features
Providing a uniform build systemMaven allows a project to build using its project object model (POM) and a set of plugins that are shared by all projects using Maven, providing a uniform build system. Once you familiarize yourself with how one Maven project builds you automatically know how all Maven projects build saving you immense amounts of time when trying to navigate many projects.
Providing quality project informationMaven provides plenty of useful project information that is in part taken from your POM and in part generated from your project’s sources. For example, Maven can provide:
- Change log document created directly from source control
- Cross referenced sources
- Mailing lists
- Dependency list
- Unit test reports including coverage
Other products can also provide Maven plugins to allow their set of project information alongside some of the standard information given by Maven, all still based on the POM.
Providing guidelines for best practices developmentMaven aims to gather current principles for best practices development, and make it easy to guide a project in that direction.
For example, specification, execution, and reporting of unit tests are part of the normal build cycle using Maven. Current unit testing best practices were used as guidelines:
- Keeping your test source code in a separate, but parallel source tree
- Using test case naming conventions to locate and execute tests
- Have test cases setup their environment and don’t rely on customizing the build for test preparation.
Maven also suggests some guidelines on how to layout your project’s directory structure so that once you learn the layout you can easily navigate any other project that uses Maven and the same defaults.
Allowing transparent migration to new featuresMaven provides an easy way for Maven clients to update their installations so that they can take advantage of any changes that been made to Maven itself.
Installation of new or updated plugins from third parties or Maven itself has been made trivial for this reason.
download maven
Download:
https://maven.apache.org/download.cgi
Installation Instructions:
https://maven.apache.org/download.cgi#Installation
Once maven is successfully installed, you should be able to run following command successfully:
mvn --version
https://maven.apache.org/download.cgi
Installation Instructions:
https://maven.apache.org/download.cgi#Installation
Once maven is successfully installed, you should be able to run following command successfully:
mvn --version
create and build simple application using maven
run following command:
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
this will create the folder named my-app and create a simple project structure underneath
inside the folder it also creates a file named pom.xml that is the main file that maven uses for everything related to your project
following command will pull all the dependencies and build your project:
mvn package
after this command runs you should have a new folder "target" created with a jar file in it
you can now run your application with either:
java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App
or
java -cp my-app-1.0-SNAPSHOT.jar com.mycompany.app.App
depending on where you are at in your terminal
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
this will create the folder named my-app and create a simple project structure underneath
inside the folder it also creates a file named pom.xml that is the main file that maven uses for everything related to your project
following command will pull all the dependencies and build your project:
mvn package
after this command runs you should have a new folder "target" created with a jar file in it
you can now run your application with either:
java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App
or
java -cp my-app-1.0-SNAPSHOT.jar com.mycompany.app.App
depending on where you are at in your terminal
gradle
JSON based alternative to maven that is gaining momentum is http://gradle.org/ we will not be covering it in this class because it has not yet become as popular as maven is today.