How can I deploy my angular 2 app on tomcat or jboss? - angularjs

I have built a basic angular 2 app. However I need to deploy it on Jboss or Tomcat as I need to use it along with my Java EE application.
Thanks for your help.

You would use a bundler such as angular-cli or webpack to create the production bundle which is then served by the HTTP server. The bundler creates all required file that go into the htdocs directory. Normally Angular apps are completely decoupled from your backend server so there shouldn't be any JBoss or Tomcat specifics.
The Angular team are going to increasingly focus on angular-cli as the premier bundling solution so it might be a good idea to start there.

If you are using angular-cli you can use ng build command. It creates all static files for deploy Angular2 app into the dist folder. You must copy and paste them in webresources folder of your Web Application (WAR). At the moment I am looking for how to deploy this files easier.

Related

How to deploy angularjs app in production without port

I'm having an application built with AngularJS (not Angular 2) and is ready to get deployed. In Angular 2+, we'll be building the project and the output of that build command will be a set of html, js, css files with assets folder. I can keep them in my webroot(htdocs in case of Apache server) and run the application. But how to do the same in AngularJS app?
Please note that I don't want to use npm start which actually runs on a port. I've an Apache server and I wanted to place my code in that folder (say htdocs/myAngularJSApp) and I want to access it using www.mydomain.com/myAngularJSApp.
Please help. Thanks in Advance.
Actually, no need to build. Just host it and it will work.

Where to install Angular on Apache?

First of all, my question is not about how to install angular. I'm just getting started with this framework and already got a question right at the beginning.
Usually I create new web projects (HTML, PHP...) in the default web folder of the apache webserver (/var/www/). I did this with angular too under /var/www/firstAngularProject, but it seems the application itself is only accessible on its default port on the webserver root. In my case this is localhost:4200
When I try to open the path in my browser localhost/firstAngularProject I see the index structure and I think this could become a security issue.
So my question is where should I install the angular project or what is the usual way to install it?
When you run Angular using the cli command ng start (which I assume, based on you describing using localhost:4200) you're running the application using webpack-dev-server. This is undesirable since it's only meant for use during development, not for production.
In production Angular works just like any other frontend framework. You build the application with ng build --prod which produces a number of build artifact (in the /dist folder). These artifact are simply static files you make available through some webserver, in your case Apache, by copying the content of the /dist folder to /var/www (or whichever is your default web folder) and that's about it.

How to publish Angular project?

I maked angular project. I used this generator:
https://github.com/swiip/generator-gulp-angular#readme
I have serwer and domain. My question is: How publish this working project on serwer? Should I use Apache http?
Since you used Gulp, you can check its docs to find out exactly you can build your Gulp application and deploy it to server.
On your command line run this in your working directory of the app
gulp //to build an optimized files to be deployed on to the server
Now in your dist folder in your root of your working directory, you'll find all the files and folders that have been created by gulp task default.
Now you can deploy this on with Apache or node or Nginx or any other server you want. Simply paste all the files to the to the
path/of/the/root/on/server
You can also preview your app the browser and watching for files changing and auto-reloading the browser to review changes by running
gulp serve
More grunt tasks here.

Single page application using grunt and tomcat

We are building single page application, using AngularJS and Spring Rest services along with spring boot. For front end build we are using grunt and for server site build maven. But we are not sure hove to build single WAR file which contains build out put from gunt and our java output.
Deployment server Tomcat.
Regards
Mahesh
You can give a try using maven-grunt plugin.
https://github.com/allegro/grunt-maven-plugin
I have the exact same setup. I am invoking grunt from maven.
From maven I invoke frontend-maven-plugin it actually downloads node binary and all node packages. And invokes grunt and bower. This essentially helps me build my project in any environment without installing node(even in Jekins server). Configure warSourceDirectory to read grunts output.

Yeoman angular grunt-serve vs http-serve

I've just used Yeoman to create an Angular project that looks great when I run grunt serve. But then I decided to view it by running http-server, and the page gets displayed without the formatting and without the images. Does anyone know why that is and if I'll run into this issue when I push it up to my web hosting server?
I discovered that I had to run grunt to build the project which fixes the references and places a distribution uglified version of the project in a dist folder. This ran just fine on my other server.
"Does anyone know why that is and if I'll run into this issue when I push it up to my web hosting server?"
Yes, you will run into this problem on your web hosting server.
grunt-serve serves the app used the setup on your local machine.
http-server mimics how a real web hosting server would evaluate your references.
My development routine is to use grunt-serve until I have a working version and then use http-server to test it out and see if it would work before I push it to my web hosting server. As #cdavid mentioned, running grunt build from your dist directory should be sufficient for general dependency issues.

Resources