Deploy angular app in tomcat

The following two tabs change content below.
Prasad Kharkar is a java enthusiast and always keen to explore and learn java technologies. He is SCJP,OCPWCD, OCEJPAD and aspires to be java architect.

Latest posts by Prasad Kharkar (see all)

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.
  • Tomcat does not support javascript dependency management or typescript
  • Even though we develop angular apps using typescript, they are ultimately converted into javascript. Hence when we deploy angular app in tomcat, we are actually putting javascript files in it.

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 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.

build angular app

build angular app

 

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

 

Share Button

1 comment for “Deploy angular app in tomcat

Leave a Reply

Your email address will not be published. Required fields are marked *