Play is a highly popular and widely used framework that facilitates building web applications with Java and Scala. Taking into consideration that this framework is in a great request among developers, today we'll consider several approaches to easily run Play applications with the help of Jelastic Cloud hosting: the first approach is based on another increasingly popular technology - Docker containers, whilst the second option presupposes running your Play project inside a Virtual Private Server (VPS).
Both these solutions provide you with the full root permissions and isolation from other accounts on the hardware. So, make up your mind on a suitable solution and proceed to one of the following instructions to run your Play application inside Jelastic.
- generate an SSH keypair
- add your public SSH key to the dashboard
- access your account via SSH protocol
Running Play Framework with Docker Containers Hosting
As a base for running Play Framework with the help of Docker containerization technology, you’ll need an image with the following basic components:
You can either build Docker image on your own or deploy the ready-to-use template we’ve prepared for you and placed within the Jelastic public repository on Docker Hub. So, when you decided on the image to utilize, proceed with the following steps to launch Play.
1. Click New Environment, switch to the Docker tab, and select one of the layers on the left for an image to be placed to.Click Select Container.
2. In the opened dialog box, switch to one of the following tabs depending on where the preferred base template it stored:
- Search - to fetch an image from public repository on Docker Hub (specify jelastic/sbt to use the dedicated Jelastic image we’ve mentioned above)
- Custom - for an image from your custom Docker registry
Tick plank with the required template and click Next.
3. Here, set resources limit for a container to be vertically scaled, specify Environment Name and a region it should be placed at. Click Create.4. After your new environment appears at the dashboard, access it via SSH Gate to download and unpack your Play application (we’ll use Play Java Starter Project as an example) within destination directory of created Docker container.
wget https://example.lightbend.com/v1/download/play-java-starter-example -O play-java-starter-example.zip
unzip play-java-starter-example.zip5. Launch the Play development console by running the following command inside the directory with unzipped project files.
cd play-java-starter-example
./sbt
When downloading of all the required dependencies is finished, you’ll see your project was set as a current one.6. At this point, the Play console is up and you can run your application in the development mode - let’s start it on port 80 (which is commonly listened by default).
run 80And for being able to open your application via web-browser, you need to disable default Play filter for allowed hosts. Access container file system with the Config icon next to the appropriate node and add the following line to the /root/play-java-starter-example/conf/application.conf file:
play.filters.disabled+=play.filters.hosts.AllowedHostsFilter
Save the changes and Open your environment in browser with the appropriate option.As you can see, the Play Java Starter Project has opened successfully.
And below we’ll consider an alternative approach of running Play Framework on top of Virtual Private Server.
Running Play Framework on top of VPS
To deploy your Play application within an isolated VPS container, proceed with the following steps.
1. Click New Environment, enable Elastic VPS at any wizard tab and select one of the available stacks according to your OS preferences (for this example, we’ll utilize CentOS as a commonly used distribution for dedicated servers).Designate vertical scaling resources limits for this node, specify hardware region and desired Environment Name. Confirm the set parameters to Create it.
Upon the creation is finished, you’ll also receive an email notification with credentials for your Private Server administrating.
2. Now, connect to your VPS container via SSH Gate and install Java SDK by running the following commands.
cd /opt
3. Download your project (we’ll use Play Java Chatroom Project example) and unpack it by running the next commands.
wget https://example.lightbend.com/v1/download/play-java-chatroom-example -O play-java-chatroom-example.zip
unzip play-java-chatroom-example.zip
4. Start the Play development console by executing the following command inside the directory with unzipped project resources.
cd play-java-chatroom-example
./sbt
As a result, your application will be complemented with the required resources and defined as a current Play project. 5. So, the Play console has been launched and now you can run your project in the development mode on the required port - e.g. the commonly used 80th one.
run 80And to gain the ability to open your application directly from Jelastic dashboard, return to it and go to the /opt/play-java-chatroom-example/conf/application.conf directory (by selecting the Config option next to the appropriate server).
Here, add automatically attached Public IP address to the list of allowed hosts and Save the changes.
Now you can use this IP address to open your application in a new browser tab.That’s it! The basic Java Chatroom Project is up and can be accessed through web browser.
In the similar way, you can host any Play application inside Jelastic Cloud with the preferred hosting technology - try it yourself by getting an account at one of our partner’s Cloud Hosting Platforms.