Spring Boot multi module WAR Generation - maven

I have made a maven Spring boot (REST) Project that has 3 (maven) sub modules (i. api ii. implementation and iii. service modules).
The main method (#SpringBootApplication) is in the root of the project. The REST web service works fine from IDE but maven does not allow me to package this project as war and deploy to external tomcat.
To solve this I added a new module and added dependencies of other modules within this and packaged this as war (by adding maven-war-plugin). But when deployed on server; the webservice does not get hit.
Structure-
Service Project
main()(This is within root project)
api module
service module
implementation module
Newly added module (that has above 3 modules injected as dependency and the plugin that let me package this as a war)
Expecting a war that has all these submodules that can be deployed on external Tomcat 9 server.
How to achieve this?
Please Note - I have added spring-boot-maven-plugin
to repackage in the root project, but it is not working.

Adding parent to this newly added module fixed the issue and I was able to make a working jar!

Related

Spring Boot Gradle plugin - live reload of resources with multi-module project

I am having problems getting live reload of static resources to work with a gradle multi-module project.
Here is my simplified project structure:
project
- application
- src/main/java/com/mypackage/MyApplication.java
- web
- src/main/resources/index.html
If I am running the spring boot gradle plugin bootRun task to launch my application in place, via the command line, the live reload of static resources within web resources does not get picked up.
Now I know if the spring boot application were to exist in web also, the live reload would work.
My two questions are:
When running the application in place with bootRun and a multi-module structure, does it build the classpath from the dependency modules build/classes or use the lib/mydependency.jar?
Is there a way to configure the plugin to consider peer modules resources for live reloading?

Creating a Maven deployment parent project

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.

Maven Pom Update

I am using Spring Tool Suite (STS) for my Spring boot application development.
I am using the Spring Started Project option to select the component required for my applications. For example: if I want to develop web application, I will select the "web" check box and spring io initailzier will download all the required jars in the classpath with help of maven.
Suppose, after the project creation for WEB, If I want to add some other components in my existing web project like using Eureka, Hystrix, the required jars are not automatically setup in the classpath and couldn't use the annotation like #EnableEurekaClient as it throws error as jar is missing.
I have manually updated the pom.xml to include the Eureka starter/client/server dependency and trying to update the project (Project >> Maven >> Update Project), so that required jars will be in classpath. But it is not happening.
Any advise on it..thanks.

Spring Boot Angular2, using mvn not loading index.html

I have a mvn project with 2 modules, ui and server both building as jars. I am using Angular2 as the ui module and have added this dependency to the server spring boot module. Both modules build correctly but the ui is not included in the server module, when the server starts correctly it does not serve the index.html page when requested.
I have the ui Angular2 src under the standard mvn resource structure eg src/main/resources.
I have found 2 examples 1) SpringAngular2TypeScript which I cant get to work and 2) a gradle project.
Any suggestion would be great or a simple working example would be better.
First of all, your UI module should not be built into a JAR. It should be built into a WAR. Jars will not include any web content. Hence your index.html is not being served since it is not present in the jar in the first place.
That being said, instead on including the ui module in the server module, you can include your server module as a jar dependency in the ui module (since wars can contain jars) and deploy this WAR on your server.
Also, you shouldn't be putting all your angular code in src/main/resources. It should be put into src/main/webapp folder. See the Standard Maven Folder Structure.

How to setup a Spring multimodule project?

I'm new to Spring and try to setup a project which is split into 3 submodules. As build tool I'm using maven. My problem is, that I don't know where to add Springs "magic".
My 3 submodules are "ORM" (holds all the hibernate staff to access the database) "BusinessLogic" (which should hold the complete logic) and "WebApp" (adds as the only "client" to the app / logic).
I want to use SpringMVC for the WebApp which seems to be no problem. As "BusinessLogic" should hold the complete logic I thought of adding the Spring related stuff (Bean definition / DI) in that module. But then I don't know how to setup Spring when accessing the module form the webapp.
The hole project is being ported from a JavaEE / JBoss app where "ORM" and "BusinessLogic" (implemented as EJBs) where put into one .ear archive and the webapp into a seperate one (.war). JNDI was used to access the beans from the webapp, but I completely want to decouple the application from JBoss and deploy it on a Tomcat webserver.
At the moment I've created all three modules as separate Maven projects ("ORM" and "BusinessLogic" as .jar, "WebApp" as .war packaging), linked by a "parent" project.
Thanks for any hints on project setup :).
Greetings
Ben
you could configure spring context in your web.xml and you can perform import of Spring sub-modules context. You can add import's configuration of sub-modules in your webApp application context.

Resources