genobis
7/26/2017 - 6:48 AM

Kopiowanie zależności - biblioteki upakowane w ./lib oraz (ewentualnie) dodatkowych plików maven-dependency-plugin maven-jar-plugin maven-re

Kopiowanie zależności - biblioteki upakowane w ./lib oraz (ewentualnie) dodatkowych plików maven-dependency-plugin maven-jar-plugin maven-resources-plugin

<?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">
    <!-- whatever -->
    <build>
        <plugins>
            <!-- kopiuje biblioteki do ./dist/lib -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/dist/lib</outputDirectory>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>false</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            
            <!-- wynikowy jar w ./dist/, manifest odnosi się do ./dist/lib -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.0.2</version>
                <configuration>
                    <outputDirectory>${project.build.directory}/dist</outputDirectory>
                    <archive>
                        <manifest>
                            <mainClass>com.example.app.Main</mainClass>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            
            <!-- kopiowanie katalogu example do ./dist/example -->
            <plugin>
              <artifactId>maven-resources-plugin</artifactId>
              <version>3.0.2</version>
              <executions>
                <execution>
                  <id>copy-resources</id>
                  <phase>package</phase>
                  <goals>
                    <goal>copy-resources</goal>
                  </goals>
                  <configuration>
                    <outputDirectory>${project.build.directory}/dist/example</outputDirectory>
                    <resources>
                      <resource>
                        <directory>example</directory>
                        <filtering>false</filtering>
                      </resource>
                    </resources>
                  </configuration>
                </execution>
              </executions>
            </plugin>
        </plugins>
    </build>
</project>