Skip to content

Instantly share code, notes, and snippets.

@ViveK-PothinA
Created March 8, 2022 20:31
Show Gist options
  • Save ViveK-PothinA/8eca07cb61bee810516f8c45880de131 to your computer and use it in GitHub Desktop.
Save ViveK-PothinA/8eca07cb61bee810516f8c45880de131 to your computer and use it in GitHub Desktop.
Standard Maven pom.xml that generates a complete target zip with dependency JARs too
<?xml version="1.0" encoding="UTF-8"?>
<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>org.example</groupId>
<artifactId>demo</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<jdk.target>1.8</jdk.target>
<jdk.source>1.8</jdk.source>
<statDeploy>${project.artifactId}-${version}</statDeploy>
<configurationSource>${basedir}\src\main\resources</configurationSource>
<targetFolder>${basedir}\target</targetFolder>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${jdk.source}</source>
<target>${jdk.target}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<mkdir dir="${targetFolder}\conf" />
<copy todir="${targetFolder}\conf">
<fileset dir="${configurationSource}" excludes="static/**" />
</copy>
<zip destfile="${project.build.directory}\${statDeploy}.zip"
basedir="${project.build.directory}"
excludes="classes/** surefire/** antrun/** maven-archiver/** test-classes/** generated-test-sources/** surefire-reports/** *.zip generated-sources/** maven-success/** maven-status/** *.yml" />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment