Maven Basics: Create, Run Projects and Understand POM Coordinates & Version Rules
This tutorial walks through creating a Maven project via archetype or IDE, explains the standard directory layout, breaks down the essential elements of a pom.xml—including coordinates, dependencies, and versioning conventions—and shows how to package and run an executable JAR using the shade plugin.
This series records the process of learning Maven from zero to a practical system.
Quick start : Maven projects can be created manually, with the archetype plugin, or via an IDE. Using the command mvn archetype:generate launches an interactive prompt that asks for the groupId, artifactId and version. After confirming the defaults, Maven downloads the selected archetype from the central repository and generates a skeleton project.
For the example in the article the generated coordinates are com.ls.mavendemo (groupId) and hello-world (artifactId) with version 1.0‑SNAPSHOT. The resulting pom.xml contains about 70 lines of configuration.
IDE creation : In practice developers often use an IDE such as IntelliJ IDEA. The IDE wizard asks for the same three parameters—groupId, artifactId and version—and creates the same directory structure automatically.
Directory structure : Maven enforces a standard layout. Under src/main/java reside the production source files, under src/test/java the test sources, and src/main/resources holds configuration files, templates, etc. The IDE‑specific .idea folder is not part of the Maven convention and can be ignored.
Basic pom.xml composition : The core elements are: <project>: root element defining the POM model. <modelVersion>: Maven 3 uses version 4.0.0. <groupId>, <artifactId>, <version>: the three coordinates that uniquely identify a build artifact. <name>: human‑readable project name. <dependencies>: list of required libraries, each described by <dependency> with its own groupId, artifactId, version and optional <scope> (e.g., compile or test). <build> and <pluginManagement>: default plugins such as maven-compiler-plugin, maven-surefire-plugin, etc.
The article then cleans the pom by removing the pluginManagement section, the url element, and the properties block that are not needed for the simple demo.
Coordinates explained : The three‑dimensional analogy shows that <groupId> usually follows the reverse‑domain pattern (e.g., org.springframework.boot), <artifactId> identifies a module within the project, and <version> specifies the artifact version. Using Spring Boot as an example, a dependency is declared as:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.7.8</version>
</dependency>Version‑number rules : Maven follows the pattern {major}.{minor}.{incremental}-{milestone}. The article defines each part:
Major : incompatible architectural changes (e.g., Spring Boot 3 dropping Java 8 support).
Minor : backward‑compatible feature additions and bug fixes.
Incremental : tiny patches for urgent bugs.
Milestone : qualifiers such as SNAPSHOT (development), alpha, beta, release, GA. Only release and GA are considered stable for production.
Packaging a runnable JAR : Running mvn clean package first removes the previous target directory and then creates a JAR. The default JAR lacks a Main-Class manifest entry, so executing java -jar hello-world-1.0‑SNAPSHOT.jar fails with “no main manifest attribute”.
To produce an executable JAR, the article adds the maven-shade-plugin to pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.ls.mavendemo.App</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>Specifying mainClass tells the plugin which class contains the public static void main(String[] args) entry point. After rebuilding, the generated JAR can be started with java -jar … and runs successfully.
Conclusion : The article demonstrates how to use Maven’s built‑in plugins and an IDE to create, package, and run a Java project, and it explains the fundamental structure of pom.xml, the meaning of Maven coordinates, and the conventional version‑number scheme, using Spring Boot as a concrete example.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
IT Niuke
Focused on IT technology sharing, original and innovative content. IT Niuke, we grow together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
