Spring Boot Angular2, using mvn not loading index.html - spring

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.

Related

JSPs, static content, SpringBoot jars and IntelliJ

So I'm developing in IntelliJ a spring boot app. Using Gradle, I'm creating the sprint boot jar file.
I'm having problems figuring out where to put the jsps and static content such as .js files in such a way that running the jar AND running from within IntelliJ works!
It seems that in order to get SpringBoot to find jsps in a jar file I need to put the jsps inside a src/main/resources/META-INF/resources directory. For example, META-INF/resources/WEB-INF/index.jsp. I'm pretty sure the WEB-INF is now meaningless.
However, if I try to run this spring boot app from within IntelliJ, it cannot find the jsp. 404, blah blah blah. I actually have to put the jsps in the war-style webapp directory in src/main. However that directory is totally ignored during the spring boot jar build.
So.. how do developers set up their development environments that is both IntelliJ and, say, gradle bootRun friendly?
There is a guide here which should work both in IntelliJ IDEA and in the command line via the war file which can be executed as a jar (via java -jar).
As per spring boot there are Limitations when it comes to jsp's.
To overcome these limitations we need to have the configuration made in the application to render jsp by placing the jsp's under src/main/resources/META-INF/resources/WEB-INF/jsp folder.
Sample Code: Click Here
References:
https://dzone.com/articles/spring-boot-with-jsps-in-executable-jars-1
https://github.com/hengyunabc/spring-boot-fat-jar-jsp-sample

Integrating Angular 5 in J2EE application

How to integrate the Angular 5 into existing J2EE application and what will directory structure for the same .
Best practice is to create a separate Frontend WAR module which includes the Angular app (directory structure: does not matter).
In the Maven or Gradle build of that module, have it build the Angular app and then copy the resources to the static web resources directory, so the built Angular app gets included as static resources in the WAR.
For Maven, use https://github.com/eirslett/frontend-maven-plugin
For Gradle, use https://plugins.gradle.org/plugin/com.moowork.node
Advantages:
the Frontend WAR module can be integrated into the EAR, and therefore be deployed along with the backend
the Frontend WAR module can be built in parallel to the other modules (which significantly decreases build time on parallel builds)

Spring Boot multi module WAR Generation

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!

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.

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.

Resources