Maven#
What is Maven?#
Pros:
Dependency Management
Industry Standard
Well Designed Structure
Cons:
Ramp-up
Structure can be overkill
Opaque mechanisms
If the build breaks, fixing it is tough!
POM.xml#
The pom.xml
(Project Object Model) file is the core of a Maven project. It contains information about the project and configuration details used by Maven to build the project. Hereβs a basic example of a pom.xml file and an explanation of its components:
POM == Project Object Model
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>my-app</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
</project>
XML Details
Project File Structure#
Maven follows a mandatory and specific directory structure to maintain consistency and convention across projects. Hereβs an overview of the Maven project structure :
my-app
β
βββ src
β βββ main
β β βββ java
β β β βββ com
β β β βββ example
β β β βββ App.java
β β βββ resources
β β β βββ application.properties
β βββ test
β β βββ java
β β β βββ com
β β β βββ example
β β β βββ AppTest.java
β β βββ resources
β β β βββ test-config.properties
β
βββ pom.xml
Here is an explanation of the above. src/main/java: This directory contains your main application source code. The package structure should follow the standard Java package naming conventions (e.g., com.example). src/main/resources: This directory is for non-Java resources required by your application, such as configuration files, property files, XML files, etc. These resources are included in the classpath when the project is built. src/test/java: This directory contains your test source code. It follows the same package structure as your main source code. Test classes are typically named with a Test suffix (e.g., AppTest.java). src/test/resources: This directory is for resources needed by your tests, such as test configuration files, mock data, etc. These resources are also included in the classpath during the test phase. pom.xml: The Project Object Model file that contains information about the project and configuration details used by Maven to build the project. It includes dependencies, plugins, build configurations, and more.
In the CSS 490: Multithreading in GUI Application
class, we have the following directory structure.
ββββ.mvn
β ββββwrapper
ββββ.vscode
ββββlib
ββββlogs
ββββsrc
β ββββmain
β β ββββjava
β β β ββββcom
β β β ββββmrstride
β β β ββββconsole
β β β ββββgui
β β β ββββservices
β β ββββresources
β β ββββdesigns
β β ββββimages
β β ββββlevels
β β ββββplaybacks
β ββββtest
β ββββjava
β ββββcom
β ββββmrstride
ββββtarget