Das Projekt Objektmodell (POM) ist das zentrale Element eines Maven-Projekts. Es definiert grundlegende Informationen und Konfigurationen, die den gesamten Build-Prozess steuern. Üblicherweise ist das POM in XML verfasst und enthält verschiedene Tags, die spezifische Aspekte des Projekts beschreiben.
<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>
<packaging>jar</packaging>
<name>My Application</name>
<description>Ein Beispielprojekt zur Demonstration von Maven</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<!-- Weitere Abhängigkeiten können hier hinzugefügt werden -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<!-- Weitere Plugins können hier hinzugefügt werden -->
</plugins>
</build>
<repositories>
<repository>
<id>central</id>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
</repositories>
<profiles>
<profile>
<id>dev</id>
<properties>
<environment>development</environment>
</properties>
<build>
<plugins>
<!-- Plugins spezifisch für das Entwicklungsprofil -->
</plugins>
</build>
</profile>
<profile>
<id>prod</id>
<properties>
<environment>production</environment>
</properties>
<build>
<plugins>
<!-- Plugins spezifisch für das Produktionsprofil -->
</plugins>
</build>
</profile>
</profiles>
</project>Identifiziert die Organisation oder Gruppe, die das Projekt
entwickelt (z.B. com.example). Der Name sollte
domänenbasiert und eindeutig sein.
Name des Projekts oder Moduls (z.B. my-app). Sollte
innerhalb der Gruppe eindeutig sein.
Gibt die Projektversion an (z.B. 1.0.0). Ermöglicht die
Verwaltung mehrerer Versionen desselben Artefakts.
Definiert das Ausgabeformat des Projekts (z.B. jar,
war oder pom). Im Beispiel ist
jar gesetzt.
Enthält projektspezifische Einstellungen, die in anderen Bereichen des POM referenziert werden. Im Beispiel wird die Quellcode-Kodierung und Java-Version festgelegt:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>Listet alle benötigten Bibliotheken und Frameworks auf. Jede
Abhängigkeit wird über groupId, artifactId und
version definiert, optional ergänzt durch
scope:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>Gibt an, in welchen Repositories Maven nach Abhängigkeiten sucht. Standardmäßig ist Maven Central konfiguriert:
<repository>
<id>central</id>
<url>https://repo.maven.apache.org/maven2</url>
</repository>Ermöglicht das Anlegen unterschiedlicher Build-Konfigurationen, beispielsweise für Entwicklungs- und Produktionsumgebungen:
<profile>
<id>dev</id>
<properties>
<environment>development</environment>
</properties>
</profile>Umfasst Konfigurationen für den Build-Prozess, insbesondere Plugins und deren Einstellungen:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>Zusätzliche Metadaten, die das Projekt näher beschreiben:
<name>My Application</name>
<description>Ein Beispielprojekt zur Demonstration von Maven</description>Dieses Zusammenspiel der POM-Elemente standardisiert und vereinfacht den gesamten Build-Prozess in Maven.