Integrating Angular 5 in J2EE application - spring

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)

Related

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!

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.

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.

gwt multi-module vs single-module project

I've seen the GWT Expenses app from GWT SDK is using single module structure.
Is this a best practice? Are there any cons in having the project split into multiple maven modules, i.e:
client
shared
server
The GWT compiler and DevMode don't really care about how you structure your build system as long as all of the client and shared resources are available on the GWT classpath and the server components have been compiled into the webapp's WEB-INF/classes directory (or lib/foo.jar) if you're using DevMode's built-in Jetty server.

Resources