• Stars
    star
    193
  • Rank 201,081 (Top 4 %)
  • Language
    Java
  • License
    MIT License
  • Created about 9 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Maven Tutorial for Beginners with Examples

Maven Tutorial for Beginners - with Examples In28Minutes

Image

Installing Eclipse and Java

https://github.com/in28minutes/SpringIn28Minutes/blob/master/InstallationGuide-JavaEclipseAndMaven_v2.pdf

Course Overview

  • 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.

Step List

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.

Running Examples

Youtube Video

https://courses.in28minutes.com/p/maven-tutorial-for-beginners-in-5-steps

0. What is Maven?

Defining what Maven does is very difficult.

Every Day Developer

	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

Maven helps us do all these and more...

	Generate Projects
	Create Eclipse Workspace

1. Beginner Maven Project

What is the power of Maven?

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

Convention over Configuration

  • 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

You are ready for theory on Build Life Cycle

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.

Build LifeCycle

	Validate
	Compile
	Test
	Package
	Integration Test
	Verify
	Install
	Deploy

Lets understand pom.xml

Project Object Model (POM)

	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

Maven repository stores all the versions of all dependencies. JUnit 4.2,4.3,4.4

Local Repository - all the dependencies that are downloaded for 1st time are stored.

2. Intermediate Maven Project

  • 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

Dependency Management

	Scope
	Transitive Dependencies
	Excluding Dependency
	Dependency Versions

Sample Project Object Model

	Maven Plugins
	Convention over configuration
		Source Code
			${basedir}/src/main/java
			${basedir}/src/main/resources
		Test Code
			${basedir}/src/test

Hierarchy of POMS

	Super POM

3. Multi Module Maven Project

  • 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

4. Maven Web Application

Packaging

	War
	Ear

Running application in Tomcat

5. Tip and Tricks

Important Commands

	help:effective-settings
	help:effective-pom
	dependency:tree
	dependency:sources
	--debug

Maven Archetypes

	archetype:generate

6. Missing (To Discuss)

  • Plugins : Show in super pom.xml
  • Eclipse Integration
  • Profiles

Expectations

  • You should know Java.

Running Examples

  • Download the zip or clone the Git repository.
  • Unzip the zip file (if you downloaded one)
  • Open Command Prompt and Change directory (cd) to folder containing pom.xml
  • Open Eclipse
    • File -> Import -> Existing Maven Project -> Navigate to the folder where you unzipped the zip
    • Select the right project
  • Choose the Spring Boot Application file (search for @SpringBootApplication)
  • Right Click on the file and Run as Java Application
  • You are all Set

Troubleshooting

Youtube Playlists - 500+ Videos

Click here - 30+ Playlists with 500+ Videos on Spring, Spring Boot, REST, Microservices and the Cloud

Keep Learning in28Minutes

in28Minutes is creating amazing solutions for you to learn Spring Boot, Full Stack and the Cloud - Docker, Kubernetes, AWS, React, Angular etc. - Check out all our courses here

More Repositories

1

devops-master-class

Devops Tutorial for Beginners - Learn Docker, Kubernetes, Terraform, Ansible, Jenkins and Azure Devops
Java
2,203
star
2

spring-microservices

Microservices using Spring Boot, Spring Cloud, Docker and Kubernetes
Java
1,770
star
3

java-tutorial-for-beginners

Java Tutorial For Beginners with 500 Code Examples
1,312
star
4

java-best-practices

Best practices in Coding, Designing and Architecting Java Applications
1,254
star
5

master-spring-and-spring-boot

Spring and Spring Boot Tutorial For Absolute Beginners - 10-in-1 - Spring to Spring Boot to REST API to Full Stack to Containers to Cloud
Java
1,226
star
6

spring-boot-examples

Code Examples for everything thats written on www.springboottutorial.com
Java
1,207
star
7

spring-master-class

An updated introduction to the Spring Framework 5. Become an Expert understanding the core features of Spring In Depth. You would write Unit Tests, AOP, JDBC and JPA code during the course. Includes introductions to Spring Boot, JPA, Eclipse, Maven, JUnit and Mockito.
Java
1,142
star
8

java-a-course-for-beginners

Java Programming Tutorial for Beginners
JavaScript
1,044
star
9

JavaInterviewQuestionsAndAnswers

Java Interview Questions and Answers
Java
973
star
10

spring-boot-master-class

Understand and love the power of Spring Boot - All its features are illustrated developing a web application managing todos and a basic API for survey questionnaire. Also covers unit testing, mocking and integration testing.
Java
965
star
11

course-material

Course Material for in28minutes courses on Java, Spring Boot, DevOps, AWS, Google Cloud, and Azure.
947
star
12

SpringMvcStepByStep

Spring MVC Tutorial for beginners - In 25 Small Steps
Java
828
star
13

spring-microservices-v2

Microservices + Spring Boot 2 + Spring Cloud + Docker + Kubernetes - https://www.udemy.com/course/microservices-with-spring-boot-and-spring-cloud/. Latest Repo - http://github.com/in28minutes/spring-microservices-v3
JavaScript
714
star
14

learn

How do you achieve your career objectives? Complete career paths with amazing Cloud, Full Stack and Microservice Courses and Videos from in28Minutes
685
star
15

SpringIn28Minutes

Spring Tutorial For Beginners
Java
657
star
16

spring-interview-guide

200+ Questions and Answers on Spring, Spring Boot and Spring MVC
JavaScript
642
star
17

MockitoTutorialForBeginners

Mockito Tutorial for Beginners
Java
632
star
18

jpa-with-hibernate

Master JPA using Hibernate as the implementation. Learn the basics of JPA - entities, relationships, entity manager, annotations, JPQL and Criteria API. Take a step into the advanced world of JPA - caching, performance tuning(n + 1 queries), mapping inheritance hierarchies. Get a peek into the magic of Spring Data JPA & Spring Data Rest.
Java
630
star
19

SpringBootForBeginners

Spring Boot Tutorial For Beginners
Java
609
star
20

full-stack-with-react-and-spring-boot

Your First Full Stack Application with React and Spring Boot
Java
606
star
21

full-stack-with-angular-and-spring-boot

Your First Full Stack Application with Angular and Spring Boot
Java
605
star
22

in28minutes-initiatives

All initiatives to build a connect between industry, instructors and learners
596
star
23

java-cheat-sheet

Java Tutorial For Beginners - Companion Reference
588
star
24

JavaWebApplicationStepByStep

JSP Servlets Tutorial For Beginners - in 25 Steps
Java
534
star
25

spring-web-services

Spring Web Services - SOAP and RESTful
Java
532
star
26

spring-unit-testing-with-junit-and-mockito

Spring Unit Testing with JUnit and Mockito
Java
359
star
27

docker-crash-course

Docker for beginners - with Java and Spring Boot Applications and Microservices
Java
350
star
28

functional-programming-with-java

Learn Functional Programming with Java using a Hands-on Step by Step Approach
Java
340
star
29

kubernetes-crash-course

Learn Kubernetes and Docker with Google Kubernetes Engine deploying Spring Boot Microservices
Java
327
star
30

interview-guide

Java interview guide - 200+ Question and Answers
297
star
31

deploy-spring-microservices-to-aws-ecs-fargate

Take your first steps towards cloud with AWS ECS Fargate. Deploy REST APIs and Microservices with Spring Boot and Docker Containers to the cloud.
Java
265
star
32

SpringBootWebApplicationStepByStep

Develop your first web application with Spring Boot Magic
Java
256
star
33

spring-boot-react-fullstack-examples

All full stack examples with Spring Boot and React for articles on our website http://www.springboottutorial.com
JavaScript
255
star
34

roadmaps

Roadmaps of in28minutes courses!
245
star
35

spring-microservices-v3

JavaScript
228
star
36

JUnitIn28Minutes

JUNIT Tutorial For Beginners
Java
216
star
37

automation-testing-with-java-and-selenium

Learn Automation Testing with Java and Selenium
HTML
193
star
38

python-tutorial-for-beginners

Python Tutorial for Beginners with 500 Code Examples
182
star
39

in28minutes.github.io

Spring Boot Tutorials
HTML
171
star
40

deploy-spring-boot-aws-eb

Deploying Spring Boot Apps to AWS using Elastic Beanstalk
Java
160
star
41

getting-started-in-5-steps

How to install and get started with Java, Eclipse, Maven, JUnit, Mockito & Spring in 5 easy steps
JavaScript
154
star
42

clean-code

Learn to Write Clean Code with Java. Get Hands-on with 20+ Code Examples involving 4 principles of Simple Design, Refactoring and TDD.
JavaScript
153
star
43

first-steps-to-software-architect

How to start your journey towards software architecture?
136
star
44

MockitoIn28Minutes

Learn Mockito from In28Minutes
Java
121
star
45

learning-paths-cloud-and-devops

How to learn Cloud and DevOps
119
star
46

spring-boot-angular-fullstack-examples

All full stack examples with Spring Boot and Angular for articles on our website http://www.springboottutorial.com
TypeScript
109
star
47

in28Minutes-Course-Roadmap

A Roadmap for our Courses. Remember we focus on Java, Microservices, Web Applications and are big Spring Shop - Spring, Spring MVC, Spring Boot, Spring Cloud...
104
star
48

docker

Docker for Beginners - Learn Docker in 5 Steps
Java
101
star
49

pcf-crash-course-with-spring-boot

PCF Crash Course for Java, Spring and Spring Boot Developers - Deploy Spring Boot REST API, Full Stack Applications and Microservices to Pivotal Cloud Foundry (PCF)
Java
98
star
50

azure-devops-kubernetes-terraform-pipeline

https://github.com/in28minutes/devops-master-class
Java
87
star
51

deploy-spring-boot-to-azure

Deploy Spring Boot Applications to Azure Web Apps
Java
82
star
52

camel

Learn Enterprise Integration Patterns with Apache Camel
JavaScript
80
star
53

Design-Patterns-For-Beginners

Design Patterns for Beginners
80
star
54

JavaObjectOrientedProgramming

Learn basics of object oriented programming with Java
Java
69
star
55

learn-programming-with-python-

learn-programming-with-python​
Python
67
star
56

10-Steps-to-High-Quality-Java-Developer

You Key to Becoming a High Quality Java Developer
61
star
57

java-to-python-in-100-steps

Learn Python using your Java Knowledge
Python
58
star
58

java-technology-for-beginners

In my 15 years of designing and developing more than 100 java web applications, there are a number of terminologies, standards, frameworks, tools that I have used. I know how difficult it is for a beginner to understand them. And imagine the trouble non techies face - the business, testing teams and others. So, this guide is to demystify these terms! Enough talk. Let's Rock and Roll......
58
star
59

spring-boot-vuejs-fullstack-examples

All full stack examples with Spring Boot and Vue JS for articles on our website http://www.springboottutorial.com
Java
57
star
60

EclipseIn28Minutes

Eclipse Tutorial for Beginners - From in28Minutes
53
star
61

jenkin-devops-microservice

https://github.com/in28minutes/devops-master-class
Java
49
star
62

spring-complete-career-path

Level 1 covers Basics of Spring Developing a web application with Spring MVC Basics of Spring Boot - Autoconfiguration, Starter Projects Basic Todo Management Application with Login/Logout Model, Controllers, ViewResolver and Filters Forms - DataBinding, Validation Bootstrap to style the page Spring Security Exception Handling Level 2 (coming soon) will cover Rest APIs with Spring Boot SOAP Web Services with Spring Boot. Level 3 (coming soon) will cover Spring Cloud Microservices
Java
44
star
63

go-serverless

Go Serverless with AWS Lambda and Azure Functions - Udemy Course https://www.udemy.com/course/serverless-tutorial-aws-lambda-and-azure-functions
JavaScript
41
star
64

Tips-Database

Tips about Web Services, APIs, Microservices, Spring, Spring Boot, Maven, Eclipse etc
37
star
65

TDDin28Minutes

TDD Tutorial For Beginners - from in28Minutes
Java
31
star
66

spring-boot-to-cloud

Spring Boot to Cloud (AWS, Azure, GCP and PCF) with Docker and Kubernetes
Java
30
star
67

JavaTutorialForBeginners

Java Tutorial for Beginners with examples
Java
29
star
68

BasicWebServletsIn28Minutes

Java
28
star
69

campus-interview-guide

60 Day Learning Challenges for Campus Interviews
28
star
70

CTutorialForBeginners

C Tutorial for Beginners
27
star
71

Java-EE-Design-Patterns

26
star
72

HibernateJPAStepByStep

Hibernate Tutorial For Beginners - Step by Step with Examples
22
star
73

in28minutes.com

Awesome Courses from the Best Selling Instructor
HTML
22
star
74

RealWorldWebApplicationWithServletsAndJspIn28Minutes

Learn to Develop your first web application with Servlets and JSP
Java
20
star
75

cloud.in28minutes.com

cloud.in28minutes.com
HTML
20
star
76

jenkins-pipeline

Java
18
star
77

spring-boot-rest-api-playground

Java
18
star
78

spring-microservices-v3-old

JavaScript
16
star
79

microservice-reference-archetype

Java
14
star
80

hello-world-rest-api-aws-ecs-codepipeline

Java
14
star
81

Struts2StepByStep

Learn Struts 2 Step By Step
Java
11
star
82

jshell-for-java-programmers

An introduction to JShell for Java Programmers
11
star
83

hello-world-rest-api-azure-pipelines

Java
10
star
84

in28minutes

9
star
85

getting-started-for-beginners-v2

Updated Getting Started Guides for Beginners Recorded with Spring Boot 3 - Spring, Spring Boot, JUnit, Mockito, JPA, Hibernate ....
Java
9
star
86

spring-boot-todo-rest-api-h2-aws-codepipeline

Java
8
star
87

In28MinutesTemplate

Serves as template for my new courses
8
star
88

todo-app

Java
6
star
89

automatewithselenium.com

Learn how to automate your tests with Selenium - Java, Python, C# and JavaScript - automatewithselenium.com
CSS
6
star
90

dev-config-server-test

4
star
91

config-server

2
star
92

programmingabc.com

Master Content for our Programming Website - programmingabc.com
CSS
2
star
93

Future-Course-Preparation

1
star
94

hello-world-playground

Java
1
star