3
1

More than 1 year has passed since last update.

Mavenで依存関係含めたJarを作成する

Posted at

概要

依存関係に設定しているJarファイルを含めてJarを作成する方法を記載
単純に作成すると、依存関係無いJarファイルが作成される

実行方法

作成するPOMファイル(一部)

以下記載を<project>タグの配下に記載する
で作成する内容の詳細を記載する

   <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.2</version>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <finalName>jarFileName</finalName>
                    <appendAssemblyId>false</appendAssemblyId>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest><mainClass>jp.co.xxx.MainClass/mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>

設定内容詳細

finalName

作成するJarの名前を指定する

<finalName>jarFileName</finalName>

この例の場合はjarFileName.jarという名称のファイルが作成される

appendAssemblyId

<appendAssemblyId>false</appendAssemblyId>

これをfalseに設定しないと
-jar-with-dependenciesとサフィックスが設定され
今回だと
jarFileName-jar-with-dependencies.jarという冗長な名称のファイルが作成される

descriptorRef

<descriptorRefs>
   <descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>

上記定義を行う事により、参照しているライブラリを作成するJarに含めることができる

manifest

<archive>
    <manifest>
       <mainClass>jp.co.xxx.MainClass</mainClass>
    </manifest>
</archive>

上記定義を行うことによってmanifestファイルが作成され
実行するときのMainクラスを指定できる

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1