Welcome to a no nonsense Apache Maven guide for Java developers who like reproducible builds and dislike magic. This tutorial walks through installing Java and Maven, scaffolding a project, decoding the pom.xml file, handling Maven dependencies, running the Maven lifecycle with common Maven commands, configuring Maven plugins, and packaging and deploying artifacts for CI or production. It is build automation explained without the ritual chanting.
Pick a Java version that matches your project needs and install it like a civilized human. Then install Maven either from a binary download or via your OS package manager. To confirm the world is sane run mvn -v
. That command prints the Java version and Maven home so you can stop guessing.
mvn -v
to verify Java and Maven are visible to your shellUse your IDE wizard or a Maven archetype to scaffold a skeleton project. Archetypes give you a ready made structure so you do not waste time creating folders and pom.xml entries by hand. The project root must include a file named pom.xml that identifies the project with groupId, artifactId and version.
Think of pom.xml as the spellbook for your build. Declare dependencies with a groupId, artifactId and version and Maven will download the jars into your local repository. To avoid version conflicts across modules use a dependencyManagement section to centralize versions.
Common tips for dependencies
Maven exposes a lifecycle made of phases you invoke with simple Maven commands. Use mvn clean
to remove old artifacts, mvn test
to run tests, and mvn package
to build jars or wars. The packaged artifact will appear under the target folder so you can actually open it and admire your compiled code.
Typical sequence for a local build
mvn clean
removes previous build outputmvn test
runs unit tests during the buildmvn package
produces the final jar or war in targetPlugins are how Maven does work like compiling code, running tests, and creating assemblies. Configure the maven compiler plugin to set source and target Java versions and use the surefire plugin to run JUnit tests. Plugins live in pom.xml and are configurable so you can tune compilation, static analysis, and packaging without rewriting Maven itself.
When your artifact is ready use mvn package
for a local deliverable and configure a distribution or deploy plugin to push artifacts to a remote repository for CI or production. Use Maven profiles to vary settings for local development, staging and production so you do not accidentally deploy debug builds to real users.
mvn -v
mvn clean
mvn test
and mvn package
to run the lifecycleThis quick Maven tutorial keeps the facts you need and leaves the mysticism out. Follow these steps and you will have predictable builds, fewer surprises in the target folder, and a slightly healthier relationship with build automation.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.