Tramite le seguenti impostazioni nel file pom.xml è possibile ottenere l'export del jar inserendo nel classpath del manifest la referenza alle librerie esterne.
Vediamo un esempio semplice :
In questo modo nel jar prodotto vediamo che sarà creata una cartella lib con tutte le librerie del progetto, mentre il manifest interno al jar avrà i seguenti valori:
Vediamo un esempio semplice :
<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}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>logbackSample.TestLog</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>lib</classpathPrefix>
</manifest>
</archive>
</configuration>
</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}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>logbackSample.TestLog</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>lib</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By: userdev
Class-Path: lib/logback-classic-1.0.13.jar lib/logback-core-1.0.13.jar
lib/slf4j-api-1.7.5.jar
Created-By: Apache Maven 3.3.9
Build-Jdk: 1.8.0_72
Main-Class: logbackSample.TestLog
Nessun commento:
Posta un commento