Home
Cloud
Big Data
CI
Install
Samples
Java
Ubuntu
Maven
Archive
Maven
|
Create a client module (jar file)
Using the archetype "maven-archetype-quickstart"
POM file (sample)
Using the archetype "maven-archetype-quickstart"
$ mvn archetype:generate \ -DarchetypeGroupId=org.apache.maven.archetypes \ -DarchetypeArtifactId=maven-archetype-quickstart \ -DarchetypeVersion=1.4 \ -DgroupId=mtitek.maven.jar.samples \ -DartifactId=mtitek-maven-jar-samples \ -Dpackage=mtitek.maven.jar.samples \ -Dversion=1.0.0-SNAPSHOT \ -DinteractiveMode=false
$ 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
POM file (sample)
Once the project generated, you can adjust the POM file.
<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> <java.version>19</java.version> <!-- Spring Boot property --> <maven.compiler.source>19</maven.compiler.source> <!-- maven-compiler-plugin property --> <maven.compiler.target>19</maven.compiler.target> <!-- maven-compiler-plugin property --> <!-- maven-compiler-plugin (3.6 and later) property --> <!-- set the same version for the source, the target and the bootstrap JVM options --> <maven.compiler.release>19</maven.compiler.release> <maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format> <!-- format of maven.build.timestamp environment variable --> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13.2</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.10.1</version> <configuration> <encoding>UTF-8</encoding> <source>${maven.compiler.source}</source> <!-- optional if maven.compiler.source property is set --> <target>${maven.compiler.target}</target> <!-- optional if maven.compiler.target property is set --> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.3.0</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!
© 2010-2022
mti
tek