How to deploy angular2 application on local tomcat server?

I am developing an angular2 application with a Lite server. Now I would like to deploy this application on a tomcat server to connect to the java database. I used angular cli. I used the 'ng build -prod' command to create the dist folder. According to the udemy tutorial on angular2, the contents of this folder are all that is required to deploy the angular2 project. I place the contents of this folder in the WebContent folder of the java project and click the green button in the Eclipse IDE to start serving the files. In other projects, I can successfully deploy html and javscript files this way. But for this angular2 project, β€œLoading ...” appears and the application never starts. The console shows these errors.

GET http: // localhost: 8080 / vendor / es6-shim / es6-shim.js [HTTP / 1.1 404 3ms not found] GET http: // localhost: 8080 / vendor / reflect-metadata / Reflect.js [HTTP / 1.1 404 4 ms not found] GET http: // localhost: 8080 / vendor / systemjs / dist / system.src.js [HTTP / 1.1 404 4 ms not found] GET http: // localhost: 8080 / vendor / zone. js / dist / zone.js [HTTP / 1.1 404 not found 4 ms] GET http: // localhost: 8080 / vendor / reflect-metadata / Reflect.js [HTTP / 1.1 404 not found 1ms] GET http: // localhost : 8080 / vendor / systemjs / dist / system.src.js [HTTP / 1.1 404 not found 2ms] GET http: // localhost: 8080 / vendor / zone.js / dist / zone.js [HTTP / 1.1 404 not found 2ms] ReferenceError: system not defined.

These errors seem stranger to me, because I see the files in these places.

When I run the ng service in the angular2 cli project folder, the application works fine.

How can I expand the dist folder on the tomcat server without starting the light server, or maybe the light server needs to work at the same time? What is the best way to do this?

+2
source share
2 answers

I run a little script to create a project and then copy it to tomcat. I tell angular what the base directory will be running in tomcat.

#!/bin/sh ng build --base-href /angular/ --prod mkdir -p /home/xxx/apache-tomcat-8.0.37/webapps/angular cp -R /home/xxx/angular-clitest/dist/* /home/xxx/apache-tomcat-8.0.37/webapps/angular/ 

Once this starts, start tomcat and you can access it at: http: // localhost: 8080 / angular

+7
source

Create the dist folder with ng build --environment = prod and copy the contents of the dist folder to the tomcat / opt / tomcat / webapps / ROOT / folder.

When we press http: // localhost: 8080 / in the browser, then the index.html file will be automatically downloaded.

thanks

0
source

All Articles