Use of spring boot to create single executable jar containing all direct and transitively dependent jar files - spring-boot

How to use spring boot maven plug in to create an application which will have a single executable jar with all direct and transitively dependent jar files packaged into it and can be a standalone runnable.

Use the spring-boot-starter-parent (or copy the spring-boot plugin config from there) and then "mvn package".

Related

Creating a Executable and library from single Spring Boot codebase

I have single SpringBoot Project(has common controllers and feign clients), with an intension to use it as library in other deployable service.
With help of Gradle task i.e. 'jar' - for plain jar and 'bootjar'- executable jar, I am trying to create 2 different jar. So with the help of 2nd executable jar we can deploy them on to QA and test the changes before asking anyone else to consume the plain lib jar.
In this project I have kept #SpringBootApplicaiton -class so that it can be run as executable. But my ask is to include this only in executable jar and not in plain jar,
as plain jar will be imported in another spring boot projects, which will fail with 2 #SpringbootApplication classes.

maven: generate library jar with classes inside a package

I've created a project (springboot service).
I need to generate:
the main executable jar, already managed by spring-boot-maven-plugin
also, I need to generate a non-executable jar from some included classes (everything inside me.jeusdi.serializers package.
Any ideas?
Create a multi-module project which has two modules:
the executable JAR
The non-executable JAR

Difference between Spring boot 2.5.0 generated *jar and *-plain.jar?

I upgraded my spring boot app to 2.5.0, then is app.jar and app-plain.jar is created by gradle.
I would like to the difference between these jars.
thanks
app.jar is the archive produced by the bootJar task. This is a Spring Boot fat jar that contains all of the module's dependencies as well as its classes and resources. It can be run using java -jar.
app-plain.jar is the archive produced by the jar task. This is a plain or standard jar file that contains only the module's classes and resources.
You can learn a bit more about this in the documentation for Spring Boot's Gradle plugin.

Use of spring-boot-maven-plugin

While creating a spring boot project I define property in pom.xml as <packaging>war</packaging> with which I can create a war and thereafter deploy the war into server maybe tomcat or WAS.
But I came across a plugin named spring-boot-maven-plugin whose documentation states that it's use is to package executable jar or war archives and run an application in-place.
My query is why do we need this at all ?
If my packaging can tell me what to create and then can deploy it to run, what is the used of this plugin.
I am trying to understand a new project so wanted to be sure that every line makes sense
The maven plugin will create an "executable" archive. In the case of the war packaging, you would be able to execute your app with java -jar my-app.war. If you intend to deploy your Spring Boot application in an existing Servlet container, then this plugin is, indeed, not necessary.
The maven plugin does more things like running your app from the shell or creating build information.
Check the documentation
The Spring Boot Maven Plugin provides Spring Boot support in Apache Maven, letting you package executable jar or war archives and run an application “in-place”.
Refer this - https://www.javaguides.net/2019/02/use-of-spring-boot-maven-plugin-with.html

How to include dependent jars of my dependencies in spring boot fat jar

We are using Gradle to build spring boot application.
Our application does not require commons-io. But one of the other dependencies requires commons-io. So we've not added commons-io as dependencies. gradle build worked fine.
But when we run the spring boot using "java -jar my-fat-jar.jar", it throws classNotFound Exception for a commons-io class.
My fat jar does not contain commons-io in its lib folder.
So we just added commons-io as dependencies, now everything works fine.
But we don't want to add each such dependencies. Instead is there any way to include the dependent jars of my dependencies in lib folder of my fat jar?
Please note that we are using spring boot gradle plugin.

Resources