Include external jar in package with Spring boot2 + Maven3

Introduction

The team members were addicted to the site, and even if I tried to find out how to do it, it didn't work out, so I'll leave a note of what I did a little differently.

It's not particularly difficult, but when it fits, it fits.

environment

Java8 Maven3 Spring boot 2.0.2.RELEASE

Purpose

Include external jar in jar created with ./mvnw clean package

Creating a project

This time, you only have to include it in the package, so there is no particular implementation.

pom.xml We will set the external jar in pom.xml without implementation.

dependencies It can't be helped if it is only in the package, so I will add the information of the jar that I want to add this time to the dependency. If you update after adding it, development on Eclipse should not be a problem.

I'm not so familiar with maven variable expansion, but when setting a folder, $ {project.basedir} and $ {basedir} are often caught in the search to specify the reference folder. However, it seems that the former points to the project directory and the latter points to the pom.xml directory. For the time being, when I looked at the maven page, I often saw the former, so this time I will use $ {project.basedir}`.

Note that it seems that version and the last version of the jar name must match (an error will occur in Eclipse), so please match that.

pom.xml


<dependency>
    <groupId>com.tasogarei</groupId>
    <artifactId>hogehoge</artifactId>
    <version>1</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/lib/hogehoge1.jar</systemPath>
</dependency>

plugins The setting to mix in the jar is done from the plugin setting. There is a ʻinclude SystemScope in the configuration, just make it true`.

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <includeSystemScope>true</includeSystemScope>
    </configuration>
</plugin>

Place the jar in the set directory

This time, it is set as $ {project.basedir} /lib/hogehoge1.jar, so place an appropriate jar. Anything was fine, so I brought the jar that was in .m2 / appropriately.

Check if it is really included

That's all for the settings. Let's try it.

package Make it a jar from the mvnw command.

./mvnw clean package

Check the contents of the jar

Now that the jar has been created successfully, let's check the contents of the jar created with jar tf. When I checked, BOOT-INF / lib / hogehoge-1.jar exists, so I succeeded in including the external jar safely.

$ jar tf jartest-0.0.1-SNAPSHOT.jar | sort
BOOT-INF/
BOOT-INF/classes/
BOOT-INF/classes/application.properties
BOOT-INF/classes/com/
BOOT-INF/classes/com/tasogarei/
BOOT-INF/classes/com/tasogarei/app/
BOOT-INF/classes/com/tasogarei/app/JartestApplication.class
BOOT-INF/lib/
BOOT-INF/lib/hogehoge-1.jar
BOOT-INF/lib/javax.annotation-api-1.3.2.jar
BOOT-INF/lib/jul-to-slf4j-1.7.25.jar
BOOT-INF/lib/log4j-api-2.10.0.jar
BOOT-INF/lib/log4j-to-slf4j-2.10.0.jar
BOOT-INF/lib/logback-classic-1.2.3.jar
BOOT-INF/lib/logback-core-1.2.3.jar
BOOT-INF/lib/slf4j-api-1.7.25.jar
BOOT-INF/lib/snakeyaml-1.19.jar
BOOT-INF/lib/spring-aop-5.0.6.RELEASE.jar
BOOT-INF/lib/spring-beans-5.0.6.RELEASE.jar
BOOT-INF/lib/spring-boot-2.0.2.RELEASE.jar
BOOT-INF/lib/spring-boot-autoconfigure-2.0.2.RELEASE.jar
BOOT-INF/lib/spring-boot-starter-2.0.2.RELEASE.jar
BOOT-INF/lib/spring-boot-starter-logging-2.0.2.RELEASE.jar
BOOT-INF/lib/spring-context-5.0.6.RELEASE.jar
BOOT-INF/lib/spring-core-5.0.6.RELEASE.jar
BOOT-INF/lib/spring-expression-5.0.6.RELEASE.jar
BOOT-INF/lib/spring-jcl-5.0.6.RELEASE.jar
META-INF/
META-INF/MANIFEST.MF
META-INF/maven/
META-INF/maven/com.tasogarei/
META-INF/maven/com.tasogarei/jartest/
META-INF/maven/com.tasogarei/jartest/pom.properties
META-INF/maven/com.tasogarei/jartest/pom.xml
org/
org/springframework/
org/springframework/boot/
org/springframework/boot/loader/
org/springframework/boot/loader/archive/
org/springframework/boot/loader/archive/Archive$Entry.class
org/springframework/boot/loader/archive/Archive$EntryFilter.class
org/springframework/boot/loader/archive/Archive.class
org/springframework/boot/loader/archive/ExplodedArchive$1.class
org/springframework/boot/loader/archive/ExplodedArchive$FileEntry.class
org/springframework/boot/loader/archive/ExplodedArchive$FileEntryIterator$EntryComparator.class
org/springframework/boot/loader/archive/ExplodedArchive$FileEntryIterator.class
org/springframework/boot/loader/archive/ExplodedArchive.class
org/springframework/boot/loader/archive/JarFileArchive$EntryIterator.class
org/springframework/boot/loader/archive/JarFileArchive$JarFileEntry.class
org/springframework/boot/loader/archive/JarFileArchive.class
org/springframework/boot/loader/data/
org/springframework/boot/loader/data/RandomAccessData.class
org/springframework/boot/loader/data/RandomAccessDataFile$1.class
org/springframework/boot/loader/data/RandomAccessDataFile$DataInputStream.class
org/springframework/boot/loader/data/RandomAccessDataFile$FileAccess.class
org/springframework/boot/loader/data/RandomAccessDataFile.class
org/springframework/boot/loader/ExecutableArchiveLauncher.class
org/springframework/boot/loader/jar/
org/springframework/boot/loader/jar/AsciiBytes.class
org/springframework/boot/loader/jar/Bytes.class
org/springframework/boot/loader/jar/CentralDirectoryEndRecord.class
org/springframework/boot/loader/jar/CentralDirectoryFileHeader.class
org/springframework/boot/loader/jar/CentralDirectoryParser.class
org/springframework/boot/loader/jar/CentralDirectoryVisitor.class
org/springframework/boot/loader/jar/FileHeader.class
org/springframework/boot/loader/jar/Handler.class
org/springframework/boot/loader/jar/JarEntry.class
org/springframework/boot/loader/jar/JarEntryFilter.class
org/springframework/boot/loader/jar/JarFile$1.class
org/springframework/boot/loader/jar/JarFile$2.class
org/springframework/boot/loader/jar/JarFile$JarFileType.class
org/springframework/boot/loader/jar/JarFile.class
org/springframework/boot/loader/jar/JarFileEntries$1.class
org/springframework/boot/loader/jar/JarFileEntries$EntryIterator.class
org/springframework/boot/loader/jar/JarFileEntries.class
org/springframework/boot/loader/jar/JarURLConnection$1.class
org/springframework/boot/loader/jar/JarURLConnection$JarEntryName.class
org/springframework/boot/loader/jar/JarURLConnection.class
org/springframework/boot/loader/jar/StringSequence.class
org/springframework/boot/loader/jar/ZipInflaterInputStream.class
org/springframework/boot/loader/JarLauncher.class
org/springframework/boot/loader/LaunchedURLClassLoader$UseFastConnectionExceptionsEnumeration.class
org/springframework/boot/loader/LaunchedURLClassLoader.class
org/springframework/boot/loader/Launcher.class
org/springframework/boot/loader/MainMethodRunner.class
org/springframework/boot/loader/PropertiesLauncher$1.class
org/springframework/boot/loader/PropertiesLauncher$ArchiveEntryFilter.class
org/springframework/boot/loader/PropertiesLauncher$PrefixMatchingArchiveFilter.class
org/springframework/boot/loader/PropertiesLauncher.class
org/springframework/boot/loader/util/
org/springframework/boot/loader/util/SystemPropertyUtils.class
org/springframework/boot/loader/WarLauncher.class

Recommended Posts

Include external jar in package with Spring boot2 + Maven3
Hello World with Eclipse + Spring Boot + Maven
Configure Spring Boot application with maven multi module
Test controller with Mock MVC in Spring Boot
Asynchronous processing with regular execution in Spring Boot
Download with Spring Boot
Include image in jar file with java static method
SSO with GitHub OAuth in Spring Boot 1.5.x environment
Until you start development with Spring Boot in eclipse 1
How to boot by environment with Spring Boot of Maven
Load an external jar from a Spring Boot fat jar
Until you start development with Spring Boot in eclipse 2
Database environment construction with Docker in Spring boot (IntellJ)
Set context-param in Spring Boot
Generate barcode with Spring Boot
Hello World with Spring Boot
Implement GraphQL with Spring Boot
Get started with Spring boot
Hello World with Spring Boot!
Spring Boot 2 multi-project in Gradle
Run LIFF with Spring Boot
SNS login with Spring Boot
File upload with Spring Boot
Spring Boot starting with copy
Spring Boot starting with Docker
Hello World with Spring Boot
Set cookies with Spring Boot
Use Spring JDBC with Spring Boot
Major changes in Spring Boot 1.5
Add module with Spring Boot
Getting Started with Spring Boot
NoHttpResponseException in Spring Boot + WireMock
Spring Boot External setting priority
Create microservices with Spring Boot
Send email with spring boot
Use thymeleaf3 with parent without specifying spring-boot-starter-parent in Spring Boot
Easily develop web applications with STS and Spring Boot. In 10 minutes.
Use Basic Authentication with Spring Boot
Spring Boot Hello World in Eclipse
Spring Boot application development in Eclipse
gRPC on Spring Boot with grpc-spring-boot-starter
Create an app with Spring Boot 2
Hot deploy with Spring Boot development
Database linkage with doma2 (Spring boot)
Write test code in Spring Boot
How to make a jar file with no dependencies in Maven
See the relative redirect behavior with the server.tomcat.use-relative-redirects setting in Spring Boot
Spring Boot programming with VS Code
Until "Hello World" with Spring Boot
Inquiry application creation with Spring Boot
Get validation results with Spring Boot
Compare Hello, world! In Spring Boot with Java, Kotlin and Groovy
(Intellij) Hello World with Spring Boot
Create an app with Spring Boot
Implement REST API in Spring Boot
What is @Autowired in Spring boot?
Google Cloud Platform with Spring Boot 2.0.0
Check date correlation with Spring Boot
Implement Spring Boot application in Gradle
Include image resources in jar file
I tried GraphQL with Spring Boot