How to deploy a Eclipse Java Web Dynamic Project on Amazon EC2? - java

I'm trying to create a web project that is able to communicate with Amazon RDS. I know how to make a localhost project connect to a RDS with JDBC.
However, the problem is that I never tried to deploy my project (so that, for example someone can type somePage.com, and go to my webpage).
I have an Amazon EC2 instance, and I've already written a simple hello world jsp page. I am able to compile it and run the Eclipse Web Dynamic Project using the installed Apache Tomcat Server, and then typing localhost:8080/somePage then I can see my hello world popping up.
However, how do I deploy my project on this EC2 instance? I'm using Windows Server 2012 edition.
My whole idea is that once I have one AMI image all setup, then I can just use autoscale to scale my webpage with that AMI image.
Can anyone point me to the right direction?

Follow the steps below:
Setup Apache Tomcat on your Amazon EC2 instance.
Usually all you have to do is download the current version, unzip it, and start it by running apache-tomcat-folder\bin\startup.bat. (You can also donwload an installer and set it up as windows service. Check this link for more details).
Make sure you test it before continuing (open its address on a browser, something like http://yourinstaceaddress.com:8080/).
Export your web application .war file
In Eclipse, right click on a Web project and select Export. Then select WAR file in the Export window and then select Next. Choose the project, the .war file name and folder to export. More detailed explanation can be found here and here (with pictures).
Deploy the .war file to your Tomcat Server
The, by far, simplest way to do this is to place your .war (say myapp.war) file in your apache-tomcat-folder\webapps\ folder.
There are other ways, like via Tomcat Manager. But they can be tricky and, as a new user, you should avoid them. (Don't worry: the simple method is ok for production deployment).
Test your web app
Visit the url: say your .war's name was myapp.war. You should visit http://yourinstaceaddress.com:8080/myapp
That's it. If you ever edit the app, repeat steps 2-4 (but delete the webapps\myapp\ folder created before executing step 3).

Boxfuse does exactly what you want.
For you Java web application you literally only have to execute:
boxfuse create my-tomcat-app -apptype=load-balanced
boxfuse scale my-tomcat-app -capacity=1-16:t2-micro:cpu25-75
boxfuse run my-tomcat-app-1.0.war -env=prod
This will
Configure your application to use an ELB
Set it to autoscale between 1 and 16 t2.micro instances based on CPU usage (scale in at 25% and below, scale out at 75% and above)
Create AMI containg Tomcat and your application ready to boot
Create an ELB
Create a security group with the correct ports
Create an auto-scaling group
Launch your instance(s)
Any subsequent update will be done as a zero downtime blue/green deployment.
For your domain, you can simply map your samepage.com DNS record to the CNAME of the ELB.
More info: https://boxfuse.com/blog/auto-scaling

Related

How to deploy an application [Looking for advice]

First, I don't know anything about deployment.
Here is my application :
I got a rest API backend using Spring Boot with a MongoDB using MongoLab. My frontend is built using React (webpack, cypress).
I have this full application on gitlab in the same repo, with different folders (ie backend, frontend).
Where can I deploy this application? I guess I need to deploy separately those services. If you guys have any advice and give me some tutorials I could follow. What URL can I use like api.example.xx for back and example.xx for the front ?
Any advice is appreciated.
Thank you
Your question is too broad to get a summarised answer. I will give you a few hints that you can expand on.
For starters, since you do not know so much about deployment, I will recommend that you learn with a single machine than with multiple IP addresses. (no Docker, Kubernetes etc. just your applications on different ports)
NOTE: below are the tools you will need to familiarise your self with before this attempt.
linux terminal / GitBash for windows
SSH (communication with your server)
Git (repository managament and versioning)
Github / Bitbucket
Hosting services
Below are a few providers you can use to get you up and running although there are a turn other providers.
Linode hosting services - paid
Amazon Web services - paid/free
Netlify - paid/free
Heroku - free
All these provide you with either a terminal or GUI to deploy/maintain your applications.
Deployment
First, you will need to install all your application dependencies on the server of your choice. i.e. Databases (Mongo for your case) and other applications that support your app. (The same way you did on your local machine)
making sure that your project has the right configurations(passwords, reference URLs, etc.)
See here on How to deploy your spring-boot application
In the meantime, you can try hosting your ReactApp on Netlify and see how it works
As you said you already have it in Gitlab right,And if you want an easy solution and a way out of deploying world then you might want to consider using netlify
it makes deploying as easy as eating a piece of cake, just
Signup
Click on "New site from Git" Button
Select Gitlab in your case
Select the project you want to deploy and for netlify to install
It automatically detects build command and that's all, waits for your permission to build.
Once build is completed you can preview your application(there is a button for that in right corner) and then confirm your deployment.
*Plus it automatically deploys the changes in your git i.e pull requests,
you can choose whatever name you want your website to be(but should be available)

Java Websocket with tomcat localhost

I don't know if this is the right one to post to, correct me and I will switch!
I am using java with eclipse photon with Apache tomcat 9. I am making a application that will be connected to server (local host or make a local host on the pc) and then I will be able to send things to this local host node to store on a document. I was woundering 2 questions before I embark on this adventure that I haven't found the answer to.
Number 1: I want to use websockets, and I have tried to find an API from tomcat website but can't find it. I have looked at bunches of API's, there is a lot of free ones, but they are confusing me a bit. There is the javaEE websocket, then their is also a tomcat version (although I'm having a problem finding that now lol), but I just want it to use localhost. In all the tutorials I have watched they use javaEE (expected), but now I don't know if tomcat and websockets work in anything other then javaEE.
number 2: My application relies on there being a local host on the machine it is running on. If I configure tomcat, and have my Server file in my project explorer for eclipse and have that inside my project folder that contains the scripts etc, when I finish and compile my application on installation for the user, I am assuming I will have to create a local server on the users machine on installation; but I was woundering(hoping) that is it simpler, and the local server folder (that I saved within the compiled file that the user will download) that contains the local server configuration will be carried over to the users version when they download. I am woundering this because of setting up ports etc.
Any wisdom or tutorials please link!
For number1 you can implement pure websocket for java with helping of this https://www.baeldung.com/java-websockets.
For number2 I suggest you two options:
Use an embedded version of tomcat then you can create a jar file and give it to your users to run it in their localhosts.
Write a ant task that when users run, your project files and resources copy to tomcat.

Can i deploy my Java Spring-Boot Application in my Synology NAS?

I have a Spring-Boot Application with REST API (Maven build and MongoDB Database). I will also make a UI with Angular 2 on top of that (npm build).
What i would like to do is, to host this site, with its backend & database on a server. Can i do that on my Synology NAS (DS216j)? Or should i better buy a small computer like Raspberry Pi 3?
I have heard somewhere that we can deploy our apps in Docker, and Synology has a docker app or sth? Will this help me reaching my goal? I would like to have a step by step guide from your similar setups.
As far as I understand, you only want to get your app running on your NAS, so using Docker would be an option, but no requirement.
According to the model-specific download page, your DS216j supports Java8.
So what you have to do:
Install Java on your NAS
Package your application as standalone jar-file: If not yet done, you can do that in your pom.xml (see Spring Boot documentation for details; btw, this standalone mode is one of the best features of Spring Boot)
Now you can upload the jar-file
Run it via the command line with java -jar <jar-file-name>.jar
Just make sure that the port of your app does not conflict with the ports used by your NAS.
You could also create a Docker image from your app and run it on your NAS, it seems like your model supports Docker: https://www.synology.com/en-us/dsm/packages/Docker. But that would create some extra effort, but no added value, from my point of view.

How to ship java based web application in AWS cloud using docker

We have build java web application which provides various REST API.. I would like to have painless deployment progress.. Here is desired scene..
Users -> Load Balancer -> AS1, AS2, AS3 ...
Here AS = Application Server (Tomcat on EC2) OR Docker instances (I will prefer docker instances)
First time Desired Flow:
Developer fires maven and builds .war file
We may develop script which will generate docker image using this .war file..
Executes steps which will float this dockers behind ELB
Redeployment:
Developer fires maven and builds .war file
We may develop script which will generate docker image using this .war file..
Executes steps which will float this dockers behind ELB and destroy previous one..
I am kind of new to DevOps and may be doing some mistake in above steps. So please feel free to correct me and provide guidance to achieve this goal.
(If this is duplicate please provide link to related question)
Thanks in advance.

Deploying a java web application online

I have built a java web application on Eclipse. But i am naive in terms of making an application live i.e. deploy it online. I have tried using Cloudbees, and succeeded in deploying it at run#cloud there, but could not see it actually running. I haven't purchased any domain name as of now, therefore I would like to try it on any free domain first. If I want to make that application live, what would be the exact steps that I'll have to follow ?
Use Redhat Openshift Cloud...
Redhat Openshift is a Cloud based service which provide PAAS(Platform As A Service) i.e. Use their Server and upload our Project.
Redhat Openshift also provides MySql , Postgre and MongoDB.
It Easy to understand, Simple to Configure and Auto-Scalable.
Redhat Openshift supports:
https://dl.dropbox.com/u/24576260/Redhat%20Support.png
There are alternatives of Redhat Openshift - Google App Engine (GAE). But GAE restrict some of the class usages in Trial Verison.
Whereas Openshift have kept open and whatever user wants he can use and configure it.
Try Jelastic.
They have a free trial as well.
PS: Works for me each time.
If you have deployed successfully to RUN#cloud then your app is already running; there is no need to purchase a custom domain. If you log in to https://grandcentral.cloudbees.com/ and click on the Apps tab, you should see your new application listed; the show in new window link will open the live web page. (This will be http://appid.accountid.cloudbees.net/ where appid is whatever you chose when creating the app, and accountid is rishabh85 or whatever your CloudBees login name is.)
You can also load this page directly from Eclipse, if using the CloudBees SDK (use http://eclipse.cloudbees.com/ to download or http://blog.cloudbees.com/2012/07/getting-started-with-cloudbees-and.html for more information). Configure your account information, and open the CloudBees view (available from the CloudBees toolbar button), and you will see your running apps. A context menu item lets you open the selected app live in a web browser.
Try Google app engine. You can deploy your Web applications and you ll get a free sub domain.
As I have small knowledge of working like this, its very easy. This is to inform you that its works like your own pc. In my last company they had a Windows server.. and Tomcat & MySQL was pre installed on that server. I just place my .war in the proper place & imported the blank DB.. and its starts working :)
Checkout my blog posts on creating a web service from scratch using Cloudbees. It's a series of 7 posts that have everything you need in order to get your service up and running (including an opensource code base with almost everything you need already integrated)
If you just want the fastest way, checkout this youtube video.

Categories

Resources