Intermediate level · Module 4 of 6 · 13 guided hours
Packages and Builds with Maven
Organise code into packages with sensible access levels, and build, test and package projects with Maven.
Learning objectives
- Organise a project into packages and choose access modifiers
- Create a Maven project and add dependencies
- Run the Maven build lifecycle and produce a runnable JAR
Topics
- packages and imports
- public, protected, package-private, private
- Maven project layout
- pom.xml and dependencies
- build lifecycle phases
- runnable JAR
Lessons
-
Lesson 1 Packages and Access Modifiers
Group related classes into packages and use access modifiers to expose only what other code should use.
packageimportpackage-privatepublic API
-
Lesson 2 Maven Projects and Dependencies
Create a Maven project, understand pom.xml and add libraries as dependencies instead of copying JAR files.
pom.xmlgroupId, artifactId, versiondependency scopelocal repository
-
Lesson 3 The Maven Build Lifecycle
Run Maven's lifecycle phases from the command line and package the application as a runnable JAR.
lifecycle phasemvn packagetarget folderMain-Class manifest
Practical activity
Convert the library project from a single folder of classes into a Maven project with model, service and storage packages, then build it from the command line.
Expected outcomes
- Well-organised projects that others can build
- Confidence with Maven's standard commands
Assessment
Practical: a provided messy project must be reorganised into packages and built with mvn package; checked by building it on the instructor's machine.
Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.