Définissez comme suit dans Maven Dependency Plugin.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
<includeArtifactIds>ajd4jp,jdom</includeArtifactIds>
</configuration>
</execution>
</executions>
</plugin>
Lorsque le package mvn est exécuté avec ce paramètre, les fichiers de classe, etc. sont développés à partir des fichiers JAR dépendants tels que les bibliothèques et copiés dans le répertoire spécifié dans outputDirectory avant de créer le fichier JAR. Lors de la création d'un fichier JAR, les fichiers de classe qui se trouvaient dans les fichiers JAR dépendants sont également combinés dans un fichier JAR.
Préparez un fichier pom.xml.
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>sample</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>
<name>sample</name>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<!-- Apache Maven Dependency Plugin -->
<!-- https://maven.apache.org/plugins/maven-dependency-plugin/ -->
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-dependency-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
<includeArtifactIds>ajd4jp,jdom</includeArtifactIds>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>ajd4jp</groupId>
<artifactId>ajd4jp</artifactId>
<version>1.4.6.2019</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/ajd4jp-1.4.6.2019.jar</systemPath>
</dependency>
<dependency>
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>
<version>1.1.3</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/jdom-1.1.3.jar</systemPath>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
</project>
Créez un fichier JAR avec la commande mvn package.
$ mvn package
Si vous développez le fichier target / sample.jar créé, vous pouvez voir qu'il contient le fichier de classe qui était inclus dans le fichier jar de la bibliothèque spécifiée.
$ unzip target/sample.jar
Archive: target/sample.jar
creating: META-INF/
inflating: META-INF/MANIFEST.MF
creating: orrery/
creating: iso/
creating: org/
creating: org/jdom/
creating: org/jdom/xpath/
creating: org/jdom/input/
creating: org/jdom/output/
creating: org/jdom/adapters/
creating: org/jdom/filter/
creating: org/jdom/transform/
creating: ajd4jp/
creating: ajd4jp/orrery/
creating: ajd4jp/orrery/tool/
creating: ajd4jp/iso/
creating: ajd4jp/util/
creating: ajd4jp/format/
creating: format/
creating: com/
creating: com/example/
inflating: orrery/package-info.class
inflating: Copyright.txt
inflating: iso/package-info.class
inflating: org/jdom/IllegalAddException.class
inflating: org/jdom/DefaultJDOMFactory.class
inflating: org/jdom/EntityRef.class
(Omission)
En introduisant le plug-in d'assemblage Maven, non seulement les fichiers JAR avec une portée système, mais également les fichiers JAR dépendants dans le référentiel peuvent être regroupés.
Préparez un fichier pom.xml.
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>sample</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>
<name>sample</name>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<!-- Apache Maven Dependency Plugin -->
<!-- https://maven.apache.org/plugins/maven-dependency-plugin/ -->
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-dependency-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
<includeArtifactIds>ajd4jp,jdom</includeArtifactIds>
</configuration>
</execution>
</executions>
</plugin>
<!-- Apache Maven Assembly Plugin -->
<!-- http://maven.apache.org/plugins/maven-assembly-plugin/ -->
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-assembly-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.example.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>ajd4jp</groupId>
<artifactId>ajd4jp</artifactId>
<version>1.4.6.2019</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/ajd4jp-1.4.6.2019.jar</systemPath>
</dependency>
<dependency>
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>
<version>1.1.3</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/jdom-1.1.3.jar</systemPath>
</dependency>
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
<version>4.0.7</version>
<scope>compile</scope>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
</project>
Créez un fichier JAR avec la commande mvn package.
$ mvn package
Si vous développez le fichier target / sample-jar-with-dependencies.jar créé, vous pouvez voir qu'il contient les fichiers de classe inclus dans le fichier jar de la bibliothèque spécifiée dans la portée système et la portée de compilation.
$ unzip target/sample-jar-with-dependencies.jar
Archive: target/sample-jar-with-dependencies.jar
inflating: META-INF/MANIFEST.MF
creating: twitter4j/
creating: twitter4j/util/
creating: twitter4j/util/function/
creating: twitter4j/auth/
creating: twitter4j/management/
creating: twitter4j/json/
creating: twitter4j/api/
creating: twitter4j/conf/
creating: META-INF/maven/
creating: META-INF/maven/org.twitter4j/
creating: META-INF/maven/org.twitter4j/twitter4j-core/
creating: orrery/
creating: iso/
creating: org/
creating: org/jdom/
creating: org/jdom/xpath/
creating: org/jdom/input/
creating: org/jdom/output/
creating: org/jdom/adapters/
creating: org/jdom/filter/
creating: org/jdom/transform/
creating: ajd4jp/
creating: ajd4jp/orrery/
creating: ajd4jp/orrery/tool/
creating: ajd4jp/iso/
creating: ajd4jp/util/
creating: ajd4jp/format/
creating: format/
creating: com/
creating: com/example/
creating: META-INF/maven/com.example/
creating: META-INF/maven/com.example/sample/
inflating: META-INF/LICENSE.txt
inflating: twitter4j/JULLoggerFactory.class
inflating: twitter4j/SymbolEntity.class
inflating: twitter4j/MediaEntity.class
inflating: twitter4j/TwitterBase.class
inflating: twitter4j/Dispatcher.class
inflating: twitter4j/HttpClientBase.class
(Omission)
Recommended Posts