Creating a Executable and library from single Spring Boot codebase - spring

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.

Related

kotlin maven compiler unresolved reference to local dependency

Googled all the Internet, I don’t know how to fix it.
The bottom line: there are 3 spring boot applications (microservices) written in Kotlin with this folder structure
parent-folder:
-api
-service1
-service2
parent-folder is just a folder for convenience in which microservices are added.
api is a spring boot application, but in it only utility classes are common for all other microservices
in the folder with api I do mvn install, the jar is installed and gets into the .m2/ folder
this is the installed service I add to the service1 dependency and when I try to do
mvn install, in the folder with service1 I get the error Error: (4,21) kotlin: Unresolved reference: api
for clarity, here is a screen of the pom Api service
dependency in service1
compile plugin of service1
when I try to make mvn install in service1 I get an error which indicates to
maven kotlin compiler just does not see the package, but everything is working in the intellij idea if i run it as application, I don’t know what i should to do; why the kotlin maven compiler does not want to get the dependency from the local maven
inside jar api there are such classes
in my case the solution was in logic of jar generation
api service was a spring project, when i try to do mvn clean install it creates jar with structure:
api.jar
-META-INF
-BOOT-INF
but when another service use it maven cant find required packages because it was looking in in package name but not in META or BOOT folders
IMPORTANT NOTE!
when you create folders inside project like src/main/kotlin maven-kotlin-compiler will create generated classes in jar inside META folder, but if you create src/main/java it will create jar that will contain generated classes inside folder that have same name that your package name

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

Spring Boot - will the executable jar be exploded in after deployment?

From the documentation of Spring Boot, I can see the directory of the executable jar will be the working directory when you start the Spring Boot application. I would like to understand, whether there are configurations/flags to explode/unpack the jar on deployment, so that I can find access the contents of the executable jar in the file system ?
There are not flags to explode the jar automatically but you can extract it yourself using the jar command. This reference may be helpful http://docs.spring.io/spring-boot/docs/current/reference/html/executable-jar.html in understanding the structure and what you can do.

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

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".

mvn jboss:deploy fails with NoClassDefFoundError

When deploying an EJB project to JBoss using JBoss Maven Plugin, I get a NoClassDefFoundError on my JBoss' console about a class that is in one of the dependencies of this EJB project.
This dependency is declared with a Compile scope. Is there another scope that I should use so that my dependencies are also deployed to JBoss? Or how should I solve this?
The error looks like this:
DEPLOYMENTS IN ERROR:
Deployment "vfszip:/Users/hordine/projects/SoftBudget/soft-budget-ejb/target/soft-budget-ejb.jar/" is in error due to the following reason(s): java.lang.NoClassDefFoundError: br/com/pedra/j2eepatterns/facade/IEntityService
I understand that you have packaged the EJB as a jar file. This means there is no any provided dependency as same as a stand-alone jar.
AFAIU, there may be 3 possible ways as the following: -
Package them as an ear and put those dependencies inside the ear/lib. Please see Maven EAR Plugin for further information.
Package them as an war and put those dependencies inside the WEB-INF/lib. Please see Maven WAR Plugin for further information.
Package them as an jar and put those dependencies inside the classpath or application server lib. Please refer to your application server document.
EDITED:
If you are using the JavaEE 6, then it is possible to package the EJB as a war file. The The Java EE 6 Tutorial: Packaging Enterprise Beans in WAR Modules told us as
Enterprise beans often provide the business logic of a web application. In these cases, packaging the enterprise bean within the web application’s WAR module simplifies deployment and application organization. Enterprise beans may be packaged within a WAR module as Java programming language class files or within a JAR file that is bundled within the WAR module.
To include enterprise bean class files in a WAR module, the class files should be in the WEB-INF/classes directory.
To include a JAR file that contains enterprise beans in a WAR module, add the JAR to the WEB-INF/lib directory of the WAR module.
WAR modules that contain enterprise beans do not require an ejb-jar.xml deployment descriptor. If the application uses ejb-jar.xml, it must be located in the WAR module’s WEB-INF directory.
I hope this may help.

Resources