SpringBoot fully executable jar without dependencies inside
You may want to consider using Spring Boot Thin Launcher. It creates a jar file with your application code but none of its dependencies. It adds a special thin launcher that knows how to resolve your application's dependences from a remote Maven repository or from a local cache when the jar is executed. Judging by the description of what you want to do, you'd utilise the local cache option.
The configuration of Spring Boot's Maven plugin to produce a fully executable jar that uses the thin launcher looks like this:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot.experimental</groupId>
<artifactId>spring-boot-thin-layout</artifactId>
<version>1.0.3.RELEASE</version>
</dependency>
</dependencies>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</build>
Related videos on Youtube
humkins
Updated on June 04, 2022Comments
-
humkins almost 2 years
NOTE: Please, before marking this question as a duplicate make sure you know the difference between executable JAR and fully executable SpringBoot JAR.
The official Spring Boot documentation describes how to build fully executable JAR. Then generated JAR file can be linked from
/etc/init.d/
and started/stopped/restarted/statused as a normal unix service without additional scripts or tools like JSVC.But the generated JAR contains all libraries and can be big enough in size (in my case 70Mb+).
I want to generate such fully executable JAR without libraries, but then to be able to run it as SystemV service on Linux and link external libraries (JARs) somehow.
UPDATE
I want to reduce the artifact size in order to speed up deploy->test->fix cycle. Sometimes I'm working via mobile network and big file size can decrease my job speed dramatically.
In case there is no a simple configuration property or a profile or a command line option I would use a kind of hack.
At the beginning, I can generate a build containing all dependencies. Then I can unzip it and move all libraries to a special folder.
Then I need to pack it again as fully executable somehow and run with pointing to the folder with libraries.
I don't think this can be done with
jar
utility becausefile
utility recognizes fully executable jar asdata
$ file fully-executable.jar file fully-executable: data
unlike the usual jar
$ file usual.jar usual.jar: Java Jar file data (zip)
-
humkins almost 7 years@JarrodRoberson That is NOT a duplicate at all. I know how to create a simple JAR, executable JAR. But I'm asking about FULLY executable JAR. I've explained the difference between them.
-
Andy Wilkinson almost 7 years@JarrodRoberson There is a difference between a fully-executable jar file and an executable jar file. Both terms exist in Spring Boot's documentation. The former has a bash script prepended to the file and can be run with
./foo.jar
. The latter does not and can only be run withjava -jar foo.jar
. I've reopened the question as it is not a duplicate
-
-
Zenith over 5 yearsWould you please tell me what it will be for gradle project?
-
Yevgeniy over 5 years@Zenith for gradle take a look here: github.com/dsyer/spring-boot-thin-launcher
-
Jafar Ali over 4 yearswhat about dependencies?
-
Jafar Ali over 4 yearsThis will download dependencies. Can maven just add the dependencies in another folder?