Skip to main content

Command Palette

Search for a command to run...

Maven for devops

Published
β€’1 min readβ€’View as Markdown

Today, I took a deeper dive into Apache Maven, a powerful build automation tool primarily used for Java projects. I practiced building a project with Maven and deployed the final artifact to an EC2 instance for testing. Here’s what I learned and implemented

πŸ“˜ What is Maven?

Apache Maven is a build automation and dependency management tool. It simplifies the build process, especially for Java applications, by:

  • Managing project structure and build lifecycle

  • Automatically handling dependencies (via the pom.xml file)

  • Generating reproducible builds across different environments

  • Making collaboration easier with a standardized project layout

  • my-app/

  • β”œβ”€β”€ src/ β”‚

  • └── main/ β”‚

  • └── java/ β”‚ └── com/example/App.java β”œ

  • ── target/

  • # Compiled code and final build go here β”œβ”€β”€ pom.xml # Project Object Model (configuration file)

βš™οΈ Maven Lifecycle Phases I Used Today:

Maven has a default build lifecycle with phases. Here’s what I used:

Cleans up the target directory (removes old builds)

mvn clean

Compiles the source code

mvn compile

Packages the compiled code into a .jar or .war file

mvn package

result JAR file located in the target/ folder β€” ready for deployment!