Creating a Maven deployment parent project - maven

I have a Maven component service that I package up as a WAR file. I would like to create another Maven project that builds a fully deployable Jetty container with a few custom configurations and contains my component service in it so that I can test my WAR or even deploy it. My questions for this scenario are:
Is it common to want to keep the WAR build separate from the distribution build? My thoughts behind doing this is that someone may not want to use my custom configured Jetty container. Maybe they want to create their own build with Tomcat or something else.
If this is a common thing to do, what packaging type should I use for the custom Jetty container project? It seems weird to me to use JAR or WAR since that isn't the actual artifact that ends up being built. And using "pom" packaging seems equally strange since I was under the impression that that is used for parent projects of submodules.

Ad 1. Yes, this is how I usually structure the project. There is an app project which is a container for application and a separate deploy project to handle the infrastructure. Regardless if it's building a container image, deploy to app server or whatsoever.
You can see it in an example project I've once created for a Devoxx presentation.
Ad 2. Default packaging (hence jar). If all you have in a project is a pom.xml (without any classes), no additional jar will be created nor installed. In the project I've mentioned the pom.xml contains only docker image creation 'logic'. In your scenario it will be jetty related plugin. No additional artifacts will be created.

Related

Is it possible to make one fat jar with two spring boot app inside each with #SpringBootApplication main

I'm totally new to spring boot/gradle, so if i say something wrong, please feel free to correct me.
I have two spring boot projects and i'm using Spring Boot Gradle Plugin to run one by one in different ports and to also generate the respective jars.
I want to know if it's possible to generate one fat jar that can run both projects in different ports.
Here's the structure of my project:
Project
setting.gradle
Project-1
src/.../#SpringBootApplication Main
build.gradle
Project-2
src/.../#SpringBootApplication Main2
build.gradle
I included both projects in the setting.gradle, the Project-2 in the dependencies of Project-1 and tried gradle clean build, but the fat jar generated in the Project-1 doesn't include the Project-2's jar. What I expected is that when I run the fat jar it exposes the two projects in their respective ports, as if I did gradle bootRun on each project.
Is what i'm doing correct? I'm assuming that putting the Project-2 in the dependencies of Project-1 would make gradle create the fat jar I want.
Or that's not possible and I just need to use the two jars that are given to me?
Thank you for your time.
You can deploy two separate jars behind the same tomcat instance to get the same outcome. Say if you deploy my-first-jar.jar and my-second-jar.jar behind tomcat, you will get two set of endpoints like:
http://localhost:8080/my-first-jar/apis-from-first-jar
http://localhost:8080/my-second-jar/apis-from-second-jar
However, seems like what you are unable to create a fat jar correctly. By default the dependencies of the project are not included in the jar. You need to explicitly say to the build tool(gradle, in your case) to make a fat jar. Have a look here
Once fat jar of Project 1 is created, it will have files from project 2 as well, but you would be able to run only single spring boot app.
PS: You can run multiple apps my combining in a single container application if u wish. Have a look here but wont recommend you to go down that road coz its messy

Deploy multiple Spring Boot modules with Maven

I have created two separate maven modules (let's call them MODULE1 and MODULE2) which are submodules of a third integration module (SUPERMODULE).
MODULE1 and MODULE2 are both Spring Boot Web Applications. What I'm trying to achieve is to start (not build) both projects / web apps by means of SUPERMODULE.
As I see it, there are two options:
Deploy them both to the same tomcat server (probably the better & more interesting solution)
Deploy them to different tomcat servers with different ports
I found no viable example to achieve either one of these options (... by means of a single maven integration project). Hence, I would be glad if someone could point me into the right direction - or are both possibilities bad practice?
You said :
Deploy them both to the same tomcat server
(1) Build automation software
Any Build Automation tool (Jenkins, bamboo...) would allow you to create a job that deploys both your wars to tomcat (the same server or different server, you can setup your job as you wish).
Do you use an automation software ? I believe that would be the best the solution / best practices.
(2) Build an EAR - Deploy to Tomee
You said:
What I'm trying to achieve is to start (not build) both projects / web
apps by means of SUPERMODULE.
What you are really describing is an EAR!
I'll describe the idea, however, it seems Spring boot does not play well with EAR: Spring Boot EAR Packaging and https://github.com/purple52/spring-boot-ear-skinny-war
Since your 2 submodules are spring boot app, you could:
build the submodules as WAR
have your Supermodule build an EAR
include both WARs in the EAR (maven dependencies)
this however implies that you use (for instance) Tomee instead of tomcat (is that an option for you?).
as mentioned above, after some research it seems a spring-boot war does not work when packaged inside an EAR. The SpringServletContainerInitializer isn't called. So this would not be an option at the moment.

Spring Boot Migration Issue on Packaging JAR and WAR using Maven

We are trying to migrate our existing Spring MVC applications to Spring Boot application. Our existing applications are using 3.2.9, so tons of XML configurations. All the beans are defined in the XML files. What we have done is first we have upgraded our existing applications to Spring 4.2.5 version since Spring Boot will work only with Spring 4 versions.
Our requirement is to have both FAT JARs and WAR files from the build. Most of our existing customers would prefer Application Server deployment, so we have to create WAR file for them. Also for our internal testing and new deployments, we are planning to use FAT JARs.
How can we achieve them in the Maven file, we are able to provide separately as below. Is there any maven plug-in to generate both in single build?
<packaging>jar</packaging>
or
<packaging>war</packaging>
We are publishing our artifacts into Nexus repository. So, we want to have the separate repository location for JAR files and WAR files. Can we do that using the single pom.xml file?
Also another question, we have all the XML configurations under WEB-INF folder. When we are moving to the Spring Boot application, it has to be under the resources folder. How can we handle them easily. When we build FAT jars, the resources are not looked under WEB-INF because it simply ignores the webapp project.
I am looking forward for some guidance to complete the migration. Infact, we have already done that changes and it is working fine, but we are confused on this WAR / JAR generations.
Update:
I have got another question in mind, if we are converting our existing applications to spring boot, do we still have to maintain WEB-INF folder in the web-app or can move everything to the resources folder?. While building the WAR file, whether spring boot takes care of moving the resources to WEB-INF? How spring boot would manage to create the WAR file if you are putting all the resources under the resources folder.
Building WAR and FAT JAR is very easy with Gradle.
With Maven, I would try multi module setup, where one sub-module will build fat JAR and second will build WAR file.
Application logic can be as third sub-module and thus being standalone JAR with Spring configuration and beans. This application logic JAR would be as dependency for fat JAR and WAR module.
WAR specific configuration can be placed in Maven WAR sub-module.
I didn't have such requirement before, so don't know what challenges may occur. For sure I wouldn't try to integrate maven-assembly-plugin or other packaging plugins with spring-boot-maven-plugin.
Concerning location of config files, just place them into src/main/resources or it's sub-folders according Spring Boot conventions. Spring Boot is opinionated framework and will be most friendly to you if you don't try to resist defaults.
Maven does not handle this gracefully, but its far from difficult to solve. You can do this with 3 pom files. One parent pom that contains the majority of the configuration, and one each for the packaging portion of the work. This would neatly separate the concerns of the two different assembly patterns too.
To clarify -- I'm not recommending a multi-module configuration here, just multiple poms with names like war-pom.xml and fat-jar-pom.xml, along with parent-pom.xml.

How to convert Maven War project to an EAR project in Openshift?

I have created an JEE application in Openshift using the JBOSS AS 7.1 cartridge a Maven project have been generated with the War deployment format.
I need to use EJBs into the application but the War format cannot hold EJB so I changed the from War to Ear, the problem is that when I deploy the Ear the application does not Work(404 Error when I access the home page).
Is there any simple solution in order to make this work?
Or Should I create two seperate projects(one EJB project and another JSF project) and a parent POM?
Actually it is possible to package EJBs inside a WAR archive : JEE6 Tutorial, so I decided to stick with that.
Alternatively it is also possible to convert a project from WAR to EAR by using Maven's project composition (useful link).

Replacing/deploying only the changes in the already depolyed ear in Jboss 7

I am deploying the ear file each time when i making a changes as my project is multi-module and it is really tedious to upload/deployed the entire ear again in Jboss 7.Is there any way to replace only the changed jar/war/files in the already deployed ear in jboss without deploying the entire ear file again.
Thanks.
You should consider using JRebel - it allows reloading changes. After you compile any class it will automaticaly reload it, supporting modern frameworks (like reloading spring beans, etc) and application servers (JBoss included). It works as a java agent. You will find more details on producent site: http://zeroturnaround.com/software/jrebel/features/
To introduce JRebel in Maven project you just need to add jrebel-maven-plugin

Resources