Mavenプロジェクトのパッケージ化方法
7114 ワード
maven-jar-pluginとmaven-dependency-pluginプラグインを使用してパッケージ化
maven-jar-pluginは、META-INF/MANIFESTを生成するために用いる.MFファイルmaven-dependency-pluginプラグインは、依存パッケージをoutputDirectoryで指定する場所にプロジェクトpomにコピーするために使用される.xmlの下にプラグインを追加して構成します
jarがデフォルトで実行しているメインクラスを変更し、mainClassを変更する必要があります.
maven-shade-pluginプラグインを使用してパッケージ化
maven-shade-pluginによりuber-jarが生成され、プロジェクトpomに依存するjarパケットがすべて含まれる.xmlの下にプラグインを追加して構成します
同様に、起動したマスタークラスを変更すればよい
maven-jar-pluginは、META-INF/MANIFESTを生成するために用いる.MFファイルmaven-dependency-pluginプラグインは、依存パッケージをoutputDirectoryで指定する場所にプロジェクトpomにコピーするために使用される.xmlの下にプラグインを追加して構成します
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-jar-pluginartifactId>
<version>3.0.2version>
<configuration>
<archive>
<manifest>
<addClasspath>trueaddClasspath>
<classpathPrefix>lib/classpathPrefix>
<mainClass>com.example.dds.DdsMainmainClass>
manifest>
archive>
configuration>
plugin>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-dependency-pluginartifactId>
<version>3.0.2version>
<executions>
<execution>
<id>copy-dependenciesid>
<phase>packagephase>
<goals>
<goal>copy-dependenciesgoal>
goals>
<configuration>
<outputDirectory>${project.build.directory}/liboutputDirectory>
configuration>
execution>
executions>
plugin>
jarがデフォルトで実行しているメインクラスを変更し、mainClassを変更する必要があります.
maven-shade-pluginプラグインを使用してパッケージ化
maven-shade-pluginによりuber-jarが生成され、プロジェクトpomに依存するjarパケットがすべて含まれる.xmlの下にプラグインを追加して構成します
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-shade-pluginartifactId>
<version>3.1.0version>
<executions>
<execution>
<phase>packagephase>
<goals>
<goal>shadegoal>
goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.asiainfo.dds.DdsMainmainClass>
transformer>
transformers>
configuration>
execution>
executions>
plugin>
同様に、起動したマスタークラスを変更すればよい