Welcome to the Maven Learning Tool! This guide will help you get started with Apache Maven using practical examples.
- Java Development Kit (JDK): Version 11 or higher
- Apache Maven: Version 3.6 or higher
- Git: For cloning the repository
- IDE (recommended): IntelliJ IDEA, Eclipse, or VS Code
Before starting, verify your setup:
# Check Java version
java -version
# Check Maven version
mvn --version
# Check Git version
git --versionExpected output examples:
$ java -version
openjdk version "11.0.12" 2021-07-20
$ mvn --version
Apache Maven 3.8.6
Maven home: /usr/share/maven
Java version: 11.0.12, vendor: Eclipse Adoptiumgit clone git@github.com:hkevin01/maven-example.git
cd maven-example# Compile the main project
mvn clean compile
# Run tests
mvn test
# Create JAR package
mvn package# Navigate to the first simple example
cd simple-examples/01-hello-maven
# Compile and test
mvn clean test
# Run the application
java -cp target/classes com.example.HelloMavenStart with these examples in order:
- 01-hello-maven: Basic project structure and lifecycle
- 02-dependencies: Dependency management fundamentals
- 03-plugins: Plugin configuration and usage
- 04-testing: Testing strategies with Maven
- 05-resources: Resource handling and filtering
After completing beginner examples:
- 06-packaging: Different packaging types
- 07-properties: Maven properties and profiles
- 08-multi-module: Multi-module project basics
- Advanced examples: Complex real-world scenarios
Focus on advanced examples:
- Multi-module projects: Enterprise-level project structure
- Custom plugins: Creating your own Maven plugins
- CI/CD integration: Automated builds and deployments
- Performance optimization: Large-scale build optimization
maven-example/
├── docs/ # Project documentation
│ ├── getting-started.md # This file
│ ├── project-plan.md # Project roadmap
│ └── best-practices.md # Maven best practices
├── simple-examples/ # Basic Maven concepts
│ ├── 01-hello-maven/ # Basic project structure
│ ├── 02-dependencies/ # Dependency management
│ └── ... # More simple examples
├── advanced-examples/ # Complex scenarios
│ ├── 01-multi-module/ # Multi-module projects
│ └── ... # More advanced examples
├── .github/ # GitHub workflows and templates
├── .copilot/ # GitHub Copilot configuration
├── pom.xml # Main project POM
├── README.md # Project overview
└── .gitignore # Git ignore rules
- Read the README: Each example has detailed documentation
- Examine the POM: Understand the configuration
- Study the code: Look at the Java classes and tests
- Run the example: Follow the provided commands
- Experiment: Try modifying the code or configuration
- Check understanding: Can you explain what each part does?
# Navigate to an example
cd simple-examples/02-dependencies
# Read the documentation
cat README.md
# Examine the project structure
tree . # or ls -la
# Look at the POM file
cat pom.xml
# Compile and test
mvn clean compile test
# Try running it
mvn exec:java -Dexec.mainClass="com.example.MainClass"# Clean build artifacts
mvn clean
# Compile source code
mvn compile
# Run tests
mvn test
# Package as JAR/WAR
mvn package
# Install to local repository
mvn install
# Full clean build cycle
mvn clean install
# Skip tests (use sparingly)
mvn clean install -DskipTests
# Run specific test class
mvn test -Dtest=TestClassName
# Debug information
mvn clean compile -X
# Offline mode (use local repository only)
mvn clean install -o# Show dependency tree
mvn dependency:tree
# Analyze dependencies
mvn dependency:analyze
# Show effective POM
mvn help:effective-pom
# List available plugins
mvn help:describe -Dcmd
# Run specific plugin goal
mvn plugin-name:goal-name# If configured in POM
mvn exec:java
# With main class specified
mvn exec:java -Dexec.mainClass="com.example.MainClass"
# With arguments
mvn exec:java -Dexec.mainClass="com.example.MainClass" -Dexec.args="arg1 arg2"# After mvn compile
java -cp target/classes com.example.MainClass
# With dependencies (after mvn package)
java -cp target/classes:target/lib/* com.example.MainClass# After mvn package
java -jar target/example-name-1.0.0.jar# Check if Maven is installed
which mvn
# If not found, install Maven:
# - Ubuntu/Debian: sudo apt install maven
# - macOS: brew install maven
# - Windows: Download from https://maven.apache.org/# Check Java version
java -version
# Set JAVA_HOME (example for Linux/macOS)
export JAVA_HOME=/path/to/your/java/installation
# Check Maven is using correct Java
mvn --version# Clear local repository cache
rm -rf ~/.m2/repository
# Try offline mode
mvn clean install -o
# Force update dependencies
mvn clean install -U# Check Java source/target versions in POM
# Ensure they match your Java installation
# Clean and recompile
mvn clean compile
# Check for IDE-specific issues
# Import project as Maven project in your IDE# Run tests with more details
mvn test -Dtest=FailingTestClass
# Skip tests temporarily
mvn clean install -DskipTests
# Run tests in debug mode
mvn test -Dmaven.surefire.debug- Search for "Maven Tutorial" on your preferred learning platform
- Look for recent tutorials (Maven 3.6+)
- Focus on practical examples rather than theory-only content
After completing the getting started guide:
- Work through simple examples: Complete all examples in order
- Try modifications: Change dependencies, add features, experiment
- Read best practices: Review the best practices documentation
- Tackle advanced examples: Move to complex scenarios
- Contribute: Consider adding your own examples or improvements
- Stack Overflow: Tag your questions with
maven - Maven Users Mailing List: users@maven.apache.org
- GitHub Issues: For problems specific to this learning tool
- Include your environment details (OS, Java version, Maven version)
- Provide the complete error message
- Share relevant parts of your POM file
- Describe what you were trying to achieve
- Mention what you've already tried
Happy learning with Maven! 🚀