We have seen a lot of angular app development till this article and used node js as server. However, we should be able to deploy angular app in tomcat and other types of servers. In this tutorial, we will learn how to deploy angular app in tomcat.
Deploy Angular App In Tomcat:
What is the need?
As we develop angular apps using node js, some questions may come to our mind
- Why did we use node js server if we are going to deploy angular app in some other server
- Why don’t we use tomcat for angular development?
- If we developed and run apps on node js, then how will it run on tomcat and other servers?
- How can I deploy angular app on tomcat? (well we will see the solution in a while)
These questions certainly have answers,
- angular apps need a lot of dependencies, node package manager of node js server helps tremendously in dependency management and compilation of angular apps.
Deploy angular app in tomcat:
We will take our angular crud app (Please take the code from linked tutorial )for reference and simply build and deploy in tomcat.
Go to our app and run below command.
ng build --base-href=/angular/
- ng invokes angular
- build asks angular to build current app
- –base-href tells angular to create a reference directory where generated index.html file will be placed. So, in current case, generated files need to be placed in /angular folder in tomcat directory structure.
When command runs successfully, it creates all required files in dist folder as below.
We are ready to deploy angular app in tomcat. Just copy all these files and paste them in /angular folder under /webapps folder in tomcat.
Once copied, fire up the server and visit localhost:8080/angular/index.html and our bikes app should be seen running.
I hope this article helped understand how to deploy angular app in tomcat