前提
・ローカルのjarを読み込む方法はいくつかネット上に見られるが、ローカル環境だけで実行できるものでは意味がない。
実行可能jarとして実行した場合でもきちんとサードパーティのjarが実行されるようにする。
jarファイルの設置
サードーパーティ製のjarを適当な場所に配置する。
(対象プロジェクトのlibディレクトリ配下など)
pom.xmlへの記述
まずはmavenのローカルリポジトリにサードパーティjarを保存する。
pom.xmlに以下の記述をした後、maven cleanを実行する。
|
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>install-external-test1</id>
<phase>clean</phase>
<configuration>
<file>${basedir}/lib/test1.jar</file>
<repositoryLayout>default</repositoryLayout>
<groupId>com.test1</groupId>
<artifactId>test1</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<generatePom>true</generatePom>
</configuration>
<goals>
<goal>install-file</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
|
尚、複数取り込む場合はタグ内に複数のを記載すればよい。※要するに↑の緑色の部分を複数書く
タグは一意のものにすること。でなければclean時に警告される。
次に、以下の記述をタグ内に追記する
|
<dependency>
<groupId>com.test1</groupId>
<artifactId>test1</artifactId>
<version>1.0</version>
</dependency>
|
ビルド
あとはmaven clean → maven build で生成された実行可能型jarを実行すればOK