In this article, we are going to check how to deploy Angular 6 & Spring Boot REST application as a single deployment unit but however best practice is to separate Spring boot and Angular application so that we decouple the client code and server code, hence the application becomes highly scalable and manageable. But sometimes there could be scenarios for example. small application/teams it is advisable to package as a single unit and deploy them. In this article, we are going to check how to use maven resources plugin and spring boot jar packaging to build and deploy as a single unit.
Quick Snapshot
In the first part of the article, we would be creating a new Angular 6 client using Angular CLI & install prerequisites. We would be installing Node.js which is a cross-platform runtime system and runtime environment for applications written in JavaScript language and npm package manager for downloading packages.
node -v & npm –v
npm install -g @angular/cli
ng -v
/api/hello
and do maven compile to check if the build is a success. ng new
command with Angular CLI npm start
the command from the workspace. http://localhost:4200
node_modules
folder & click on apply. We wouldn’t need node_modules
a folder because it would be generated during the build process. node_modules
folder. app.component.css
to update color as ‘black’ (optional step) app.component.ts
to update the title as required (optional step) npm start
to view the changes ng build –prod
command for generating production build artifacts. /src/main/resources/static
the folder to Spring Boot Project. Following is the POM configuration <plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals><goal>copy-resources</goal></goals>
<configuration>
<outputDirectory>${build.directory}/classes/static/</outputDirectory >
<resources>
<resource>
<directory>../angular6-client/dist</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
Java –jar
the command to launch the application, you should see the Angular application served from the static folder.
Congrats! today we have learned how to use maven resources plugin and spring boot jar packaging to build and deploy as a single unit.
The sample code used in this article can be found at Github here.
Operating a business often entails balancing tight schedules, evolving market dynamics, and shifting consumer requirements.…
Of course, every site has different needs. In the end, however, there is one aspect…
In today's digital-first world, businesses must adopt effective strategies to stay competitive. Social media marketing…
62% of UX designers now use AI to enhance their workflows. Artificial intelligence (AI) rapidly…
The integration of artificial intelligence into graphic design through tools like Adobe Photoshop can save…
The cryptocurrency trading world has grown significantly in recent years, with automation playing a key…
This website uses cookies.