How to deploy Angular 8 app in Tomcat Server?
16,083
To deploy Angular 8 app in Tomcat, just execute the command below:
ng build --base-href=/app-name
- 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 /webapps/app-name folder in tomcat directory structure.
Please do note that when command runs successfully, it creates all required files in project-folder/dist folder.
Also, when you copy the files (or in this case, the folder), make sure that you restart tomcat.
Related videos on Youtube
Comments
-
SPS almost 2 years
I've completed a tutorial on Angular and I want to deploy it in my tomcat server. I use eclipse to trigger my tomcat server which opens in localhost:8080 (I use/only know java for back-end). This angular project has Firebase as back-end, not java. I intend to use java as back-end, hence I need to deploy it in tomcat. YES I have tried all the stuff I found in stack overflow and YouTube. ie,
-
ng build --prod --aot --base-href=/myapp
, putting it inwebapps/myapp/<files-from-angular-dist>
and triedroot/myapp/<files-from-angular-dist>
in tomcat. -
base href ="."
,base href ="./"
,base href ="/"
, and placed in dist folder in root and webapps and it didn't work. - Not using AOT compiler (IDK why I did that).
- Putting it in webcontent folder of my dynamic-webapp (an old java project).
What should I do ?
- Apache Tomcat version - 9.0.22
- Eclipse Dist - JUNE 2019
- Angular - 8.2.0 (got from
ng version
)
-
Mises over 4 yearsIf You no need SSR You just need a tomcat server to send to user for every not known request like localhost:4200/login file index.html.
-
Mises over 4 yearsIf You use firebase it will be easyer for You to send application on firebase hosting. In firebase hosting server are set to
"source": "**", "destination": "/index.html"
which means all non known sorce sendindex.html
file. -
SPS over 4 yearsI don't know anything about SSR in Angular. Also, how do I redirect all unknown req including 404 to index.html
-
SPS over 4 yearsI don't plan to use firebase as backend though. I am planning to develop my own back end in java.
-
Mises over 4 yearsI dont know also how to redirect not known queries to
index.html
file in tomcat server. Firebase hosting is not really a backend it just manage request to give user necessary files. I dont know are you know that Angular Single Page Application is that you send all files to user and his browser works like backend. That why You can send Angular application to firebase hosting and set up application to send http queries to your backend server to solve the buisnes logic if You dont want to display it to user. Your backend will work like REST service or macro/micro service.
-