Integrate Java and Angular Webapp in One JAR
Integrate Java and Angular Webapp in One JAR
At first create a simple spring boot project and make it as your parent project. There will be 3
projects,
● Root project
● BackEnd project
● FrontEnd project
There will be a problem, your frontEnd project won’t be added as a module because it doesn’t
contain the pom.xml file. So create the pom.xml file and configure the parent. Mention parents
package, groupId, artifactId, version properly.
<configuration>
<nodeVersion>${node-version}</nodeVersion>
<npmVersion>${npm-version}</npmVersion>
<workingDirectory>src/main/web/</workingDirectory>
</configuration>
After configuring node version and npm version, you need to add this in plugins as a plugin:
<plugin>
<!-- Frontend Maven Plugin configuration -->
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.8.0</version>
<configuration>
<nodeVersion>${node-version}</nodeVersion>
<npmVersion>${npm-version}</npmVersion>
<workingDirectory>src/main/web/</workingDirectory>
</configuration>
<executions>
</executions>
</plugin>
</plugins>
You need to edit the package.json file and put a new script on the “scripts” attribute
"scripts": {
Add build path and dist path of frontEnd in your backend pom file.
<frontend-bundle-dir>${project.parent.basedir}/bkashAmlFrontend/dist/bKashAML360Ang
ular/</frontend-bundle-dir>
<start-class>com.datasoft.aml360ApiGetway.Aml360ApiGetwayApplication</start-class>
Finally add some plugin to Gather the "dist" directory from frontend project
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals><goal>copy-resources</goal></goals>
<configuration>
<outputDirectory>${project.build.directory}/classes/resources/</outputDirectory >
<resources>
<resource>
<directory>${frontend-bundle-dir}</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
To create the package just run the command below at the project’s main directory.
mvn package
If mvn not found then just click here from root projects lifecycle:
It will take time and finally run the jar from your backend targeted folder and see magic.