- Profiles
- Surefire Plugin Reports
- Automation Testing (Selenium) Reports
- We will use Handson Real World Examples to understand what Maven can do.
- We will understand how Maven makes the life of an application developer easy.
- We will learn how Maven helps us to automate things like compilation, running unit tests, creating a war, creating an ear, running a web application in tomcat.
- We will learn how to use Maven effectively in combination of an IDE like Eclipse.
- We will use
- Maven for dependency management, building and running the application in tomcat.
- Eclipse IDE.
Lets now look at the steps in this tutorial.
- Step 1 to 4 we will learn about the basics of Maven : Project Object Model and Build LifeCycle
- Steps 5 and 6 we will learn about dependency management and transitive dependencies
- Step 7 we will learn about a maven project with multiple layers. Typical projects have a web layer, data layer, external interface layer. We will learn how to create such projects using maven. Multi Module Maven Project.
- Step 8 : We will learn how to create a war, deploy to tomcat.
- If you are downloading the zip file, unzip the file
- Open Command Prompt and Change directory to folder containing pom.xml
- Run command "mvn tomcat7:run"
- For help : user our installation guide - https://github.com/in28minutes/SpringIn28Minutes/blob/master/InstallationGuide-JavaEclipseAndMaven_v2.pdf
https://courses.in28minutes.com/p/maven-tutorial-for-beginners-in-5-steps
Defining what Maven does is very difficult.
Manages Dependencies - Web Layer (Spring MVC), Data Layer (JPA - Hibernate) etc..
Build a jar or a war or an ear
Run the application locally - Tomcat or Jetty
Deploy to a T environment
Add new dependencies to a project
Run Unit Tests
Generate Projects
Create Eclipse Workspace
First Project : My aim is to create a Spring.jar. Think as if you are developing Spring. Some other developers want to use the framework you are developing. Steps in creating a JAr
- App.Java -> App.class
- AppTest.Java -> AppTest.class
- Run Unit Tests
- Package in a particular format
- Earlier this was done using long tedious ant scripts
- Pre defined folder structure
- pom.xml
- mvn --version
- mvn compile (compiles source files)
- mvn test-compile (compiles test files) - one thing to observe is this also compiles source files
- mvn clean - deletes target directory
- mvn test - run unit tests
Pre-defined sequence of steps that are done when we run a maven command. Plugins can be attached to lifecycle stages. Default plugins are already defined in the super pom.
mvn install
- package - creates the jar
- install - copies the created jar to local maven repository - a temp folder on my machine where maven stores the files.
Validate
Compile
Test
Package
Integration Test
Verify
Install
Deploy
Name (if another project want to refer to our project, how do they do it?)
Version (Major Version, Minor Version, Incremental Version)
Packaging
Dependencies
Plugins
- Transtive Dependencies (add Hibernate dependency)
- Exclusions - Add an exclude
- Dependency Hierarchy - See how each dependency is coming in
- Versions [4.1,] [,4.1] [,4.1)
- Scope - Dependencies are needed only for tests. They are not part of the war or jar. we can use scope for that.
- Maven Compiler Plugin - Change source from 1.5 to 1.8.
- Effective Pom - Super Pom (Similar to Java Inheritance) - Check the build part of super pom (Convention over configuration - defaults are defined). We can change it - for example source directory. Recommended not to override defaults. Easy to move from one project to another project. Definitions of various plugins. mvn help:effective-pom
Scope
Transitive Dependencies
Excluding Dependency
Dependency Versions
Maven Plugins
Convention over configuration
Source Code
${basedir}/src/main/java
${basedir}/src/main/resources
Test Code
${basedir}/src/test
Super POM
- Most projects have multiple layers. Each layer has its own dependencies. Also multiple layers may share same dependency. We will see the best practices in managing dependencies in a multi module maven project.
- Parent pom has type pom
-
- Defines Modules
- Dependency Management Section
- Properties
- Pre-defined Variables ${project.version}
- Run from command prompt - mvn clean install
War
Ear
help:effective-settings
help:effective-pom
dependency:tree
dependency:sources
--debug
archetype:generate
- Plugins : Show in super pom.xml
- Eclipse Integration
- Profiles
- You should know Java.
- Thats a lot of ground we covered over the last so and so..
- To find out more about *** use these References
- We had fun creating this course and we are sure you had some fun too.
- Good Luck and Bye from the team here at in28Minutes
- Do not forget to leave us a review.
- At in28Minutes, we ask ourselves one question everyday. How do we create more effective trainings?
- We use Problem-Solution based Step-By-Step Hands-on Approach With Practical, Real World Application Examples.
- Our success on Udemy and Youtube (2 Million Views & 12K Subscribers) speaks volumes about the success of our approach.
- While our primary expertise is on Development, Design & Architecture Java & Related Frameworks (Spring, Struts, Hibernate) we are expanding into the front-end world (Bootstrap, JQuery, Angular JS).
- Best Course are interactive and fun.
- Foundations for building high quality applications are best laid down while learning.
- Problem Solution based Step by Step Hands-on Learning
- Practical, Real World Application Examples.
- We use 80-20 Rule. We discuss 20% things used 80% of time in depth. We touch upon other things briefly equipping you with enough knowledge to find out more on your own.
- We will be developing a demo application in the course, which could be reused in your projects, saving hours of your effort.
- All the code is available on Github, for most steps.
- Check out all our courses with 100,000 Students
- 25 Videos and Articles for Beginners on Spring Boot
- Our Best Courses with 66,000 Students and 4,000 5-Star Ratings
- Java Interview Guide : 200+ Interview Questions and Answers
- First Web Application with Spring Boot
- Spring Boot Tutorial For Beginners
- Mockito Tutorial : Learn mocking with 25 Junit Examples
- Java EE Made Easy - Patterns, Architecture and Frameworks
- Spring MVC For Beginners : Build Java Web App in 25 Steps
- JSP Servlets For Beginners : Build Java Web App in 25 Steps
- Java OOPS in 1 Hours
- C Puzzle for Interview