• Home
  • LLMs
  • Python
  • Docker
  • Kubernetes
  • Java
  • Maven
  • All
  • About
Maven | Create a client module (JAR file)
  1. Create a Maven Project
  2. Update the pom.xml file

  1. Create a Maven Project
    Create a new Maven Java application project using the maven archetype:
    $ mvn archetype:generate \
      -DarchetypeGroupId=org.apache.maven.archetypes \
      -DarchetypeArtifactId=maven-archetype-quickstart \
      -DarchetypeVersion=1.5 \
      -DgroupId=mtitek.maven.jar.samples \
      -DartifactId=mtitek-maven-jar-samples \
      -Dpackage=mtitek.maven.jar.samples \
      -Dversion=1.0.0-SNAPSHOT \
      -DinteractiveMode=false
    The generated project structure will look like this:
    $ find ./mtitek-maven-jar-samples/ -type f
    ./mtitek-maven-jar-samples/pom.xml
    ./mtitek-maven-jar-samples/src/main/java/mtitek/maven/jar/samples/App.java
    ./mtitek-maven-jar-samples/src/test/java/mtitek/maven/jar/samples/AppTest.java
    The archetype creates a minimal structure. Typically the project structure should look like:
    mtitek-maven-jar-samples/
    ├── pom.xml
    ├── src/
    │   ├── main/
    │   │   ├── java/
    │   │   │   └── mtitek/
    │   │   │       └── maven/
    │   │   │           └── jar/
    │   │   │               └── samples/
    │   │   │                   ├── App.java
    │   │   │                   └── SomeClass.java
    │   │   ├── resources/
    │   │   │   └── application.properties
    │   │   └── test/
    │   │       └── java/
    │   │           └── mtitek/
    │   │               └── maven/
    │   │                   └── jar/
    │   │                       └── samples/
    │   │                           └── AppTest.java
    └── target/
        └── mtitek-maven-jar-samples-1.0.0-SNAPSHOT.jar
  2. Update the pom.xml file
    Once the project is generated, you should update the pom.xml file. Here's an example:
    <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>mtitek.maven.jar.samples</groupId>
        <artifactId>mtitek-maven-jar-samples</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <packaging>jar</packaging>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    
            <!-- Spring Boot property -->
            <java.version>23</java.version>
    
            <!-- maven-compiler-plugin properties -->
            <maven.compiler.source>23</maven.compiler.source>
            <maven.compiler.target>23</maven.compiler.target>
            <maven.compiler.release>23</maven.compiler.release>
    
            <!-- format of maven.build.timestamp environment variable -->
            <maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format>
    
            <!-- Plugin versions -->
            <maven-compiler-plugin.version>3.14.0</maven-compiler-plugin.version>
            <maven-jar-plugin.version>3.4.2</maven-jar-plugin.version>
            <maven-surefire-plugin.version>3.5.3</maven-surefire-plugin.version>
            <junit.version>5.13.1</junit.version>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter</artifactId>
                <version>${junit.version}</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>${maven-compiler-plugin.version}</version>
    
                    <configuration>
                        <encoding>UTF-8</encoding>
    
                        <!-- optional if maven.compiler.source property is set -->
                        <source>${maven.compiler.source}</source>
                        <!-- optional if maven.compiler.target property is set -->
                        <target>${maven.compiler.target}</target>
                    </configuration>
                </plugin>
    
                <!-- Surefire plugin for JUnit 5 support -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>${maven-surefire-plugin.version}</version>
                </plugin>
    
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>${maven-jar-plugin.version}</version>
    
                    <configuration>
                        <archive>
                            <manifest>
                                <addClasspath>true</addClasspath>
                                <mainClass>mtitek.maven.jar.samples.App</mainClass>
                                <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                            </manifest>
    
                            <manifestEntries>
                                <Implementation-Build>${maven.build.timestamp}</Implementation-Build>
    
                                <Implementation-Title>mtitek maven jar samples</Implementation-Title>
                                <Implementation-Version>${project.version}</Implementation-Version>
                                <Implementation-Vendor-Id>mtitek</Implementation-Vendor-Id>
                                <Implementation-URL>http://www.mtitek.com</Implementation-URL>
    
                                <custom-manifest-entry>mtitek</custom-manifest-entry>
                            </manifestEntries>
                        </archive>
                    </configuration>
    
                    <executions>
                        <execution>
                            <id>default-jar</id>
                            <phase>package</phase>
                            <goals>
                                <goal>jar</goal>
                            </goals>
                        </execution>
    
                        <execution>
                            <id>test-jar</id>
                            <phase>package</phase>
                            <goals>
                                <goal>test-jar</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </project>
    Build the project:
    $ mvn clean install
    Use the command "java -jar" to test your jar:
    $ java -jar target/mtitek-maven-jar-samples-1.0.0-SNAPSHOT.jar
    Hello World!
© 2025  mtitek