Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy angular2 on tomcat?

First I'd like to describe my set up:

I have a web service, let's call it "Cars", written in Java, that I've tested in eclipse with tomcat v6, working local (it was a requirement, so that once it works locally I can switch to do it with a "real" tomcat server so others can access). It works, it access the database, it offers an answer for certain URIs and so on.

I have coded in Plunker an angular 2 application, "WebCar", and I now want to run that on my computer, with a Tomcat server (unless there is a better way of doing it, I've been told to do it with Tomcat. Since I do not know any better option, that's why I talk about tomcat all of the time). With eclipse, I have already managed to get the app running, using palantir plugin for typescript https://marketplace.eclipse.org/content/typescript , and then running the project with a server-launch.js which contains require('lite-server'); , this allows me to see the same I saw on plunker, so, it works, but before I upload anything to the business servers I wanted to check everything works (hence the set up, which may not be necessary but it's what I come up with).

I now want to go one step further and use, if possible, tomcat v6 to run my angular 2 app, instead of simply using that lite server, so that I can test that it works, and then uploading it to a "real", remote server.

I would like to know what options are there, what would be a better option, and anything that is required to make an angular 2 deployment properly. So far I've found this

  • https://stackoverflow.com/a/34408495/6028947 " You only have to deploy .js files, since anyway browser won;t" which I don't fully get,

  • http://jspm.io/ which is for SystemJS (I have an older version of Angular 2 and use config.js)

  • https://stackoverflow.com/a/37568235/6028947 which talks about angular-cli or webpack, which makes a bundle but if I got that running, I still don't know what to do with it to upload to Tomcat and then connect it to my web service.

So maybe the question should be (I don't know for sure): Once you get your angular 2 code bundled, what's next?

Btw there are a few other questions on stackOverflow, similar to this, but as far as I've seen, without any answer at all or with answers only obliquely related to this (and of course, nothing resembling a guide or step by step required)

like image 973
monkey intern Avatar asked Oct 18 '22 04:10

monkey intern


1 Answers

Thanks to @nuzz for this ..

I'm running a little script to build the project and then copy it to tomcat. I'm telling angular what the base directory is that it will run under 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 thats run, start tomcat and you can access it at: http://localhost:8080/angular

like image 57
danday74 Avatar answered Oct 27 '22 14:10

danday74