How To Deploy Your Java Application Successfully

Don't you ever wonder what goes on behind the scenes of a website or a web application? Especially for things like: how, exactly, does clicking on a button take you to a different page? And where does your personal information go when you sign up for a free trial? Well interestingly that's where the backend developers comes in.
Back-end developers are those developers who build and maintain the logics that processes data and carry out certain functions and actions when you interact with a website or a web application. Unlike front-end developers, who control everything you can see on a website, back-end developers are involved in data storage, security, and other server-side functions that you cannot see.
These sets of developers ensure the website or web application works correctly, focusing on databases, back-end logic or business logic, application programming interface (APIs), architecture, and servers and Databases. They use code that helps browsers communicate with these databases, store, understand, and delete data.
But in the beauty of all of these, it's of no use writing the business logic of an application and users can even make use of it. Hence, one problem backend developers can experience is the challenge that comes with deploying their application for public consumption be it on a free cloud server like Render or Paid cloud server like Oracle, Amazon AWS, Azure and so on.
In this article, we would look at the following;
Why this article - The Challenge
Steps in creating a Dockerfile
Likely Errors
About me
About HNG
THE CHALLENGE
Building your application is one thing, deploying it successfully is another thing. While building my first backend application, one challenge I faced was deploying this application using Docker to free cloud web hosting services like Render, so that users can easily check out on their various browsers how the application works. For four days, I kept watching different tutorials on how to solve my problem but none of the tutorials addressed the problem as straightforward as I expected.
In this article, I am going to show you how to deploy your Springboot application on render successfully using Render you are going to see the likely areas where you can go wrong when it comes to deploying your application. It is expected that you are already familiar with Git and GitHub, a little bit about Docker and then you must have tested your code on the backend to confirm it is working using Postman.
In order to avoid problems like the pictorial image below, after ensuring your application is working using postman, the next thing is to ensure the Docker file is properly set so that during deployment, render can easily locate the “Run” file of your code.

Lets see how to do that with the steps that follows:
Step 1
Ensure that the code is working properly on your local host with a “200 OK Status” using postman before deploying.

Step 2
Create a docker file with the key word “Dockerfile” on your project directory by right clicking the project folder, then click on “New”, then click on “file”, then create a new file and name it “Dockerfile”.


Step 3
Paste this code on the docker file if your build project is using Java 17. If you are using any version higher that 17, simply change the 17 to the version of JDK you are working with.
FROM eclipse-temurin:17-jdk-alpine
VOLUME /tmp
COPY target/*.jar app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
EXPOSE 8080
You should see something like this. If prompted to Enable plugin, then click it so it can be added to your code. The reason for this plugin is to easily tell your if you have a syntax error in the docker file. If there is an error, when you try to deploy it will fail because Render is relying on this docker file to host your application.

When you click Enable Plugin you should see something like this that looks more colorful.

Looking at the image above, it is very clear now there's a difference between this image and the first image that had no docker installed simply because we have a docker extension. The Docker extension not only make it colourful but also detect errors.
Detecting Errors
In detecting errors in your docker the extension makes it possible to avoid possible error that might affect application during deployment. For example, the image below give a clear explanation of that.

If for any reason you didn’t get that pop up. Simply follow the following steps:
Click the icon below on your IntelliJ idea

Go to settings. Under settings, click on
plugins
Search for
Docker
- Click on
“Enable”and click“Apply”
- Click on

This should successfully have the extension installed in the IDE
Step 4
Go to your project directory and move down to “.gitIgnore”. Delete the target command below. It is very important to do this as this will prevent render from identifying the target folder if not removed.

Step 5
Go to your maven and package the project in .jar format by clicking on the “M” icon then right click on the “Package” and click on “Run Maven Build”. The project should build and create a .jar file in the target folder of your application with a “Build Success” response.


Step 6
Now we have successfully Dockerize the application, the next thing is to open our Command terminal and push the project to our git repository using the git commands.

Step 7
Once we have done that, we should have something like this below. The highlighted folder is where the .jar of our contained application is located. Render will simply go through that directory and get the file. Initially, we had to remove the target command from .gitIgnore, if we had not done that, we would not see the “target” folder here, which means Render cant host our application because it wont be able to find the .jar file.


Step 8
Next step is to copy the repository link of our github.

and head over to Render where we must have created our account already. After creating our account on Render, click on the “New” icon and click on “Web Service”

Step 9
Click on the “Build and Deploy from a Git Repository” and click “Next”

Step 10
Paste the link of your repository you copied and paste it and click “Continue”

Step 11
Render will clone your project and build it and then host it live. If you follow this whole process completely, you should see this as an indication of build success.

Otherwise you’ll get an error on the log of Render telling you in particular the issues it encountered while working on your .jar file and what type of error.
Step 12
Click here to view your web application

If your Springboot application was deployed successfully, you should see this error page from Spring upon deploying your application.
Likely Errors You May Encounter
Error in docker file - "Unterminated Quoted String".

This error is as a result of the fact that there is an error in your docker file, could be wrong syntax or wrong command. If you have the Docker Extension plugin installed debugging the error would be easy.
Target Folder Not Found.

This error occurs when Render cannot find the target folder in your repository in github. This simply means the you forgot to remove the target command from the .gitIgnore like we discussed earlier.
Follow everything I outlined here and if you have any questions please leave me a comment and I will respond shortly.
Just in case you don't know who I am, my name is Innocent Omoyibo. I am a backend developer with 1 year experience with Java using Springboot. I just began my internship journey with HNG to grow my backend development career from experienced mentors so I can be very useful to the software community and whatever tech establishment I find myself. I am currently working an enterprise project to further increase my experience as a developer. I have learnt so much about HNG and its grits in handling its interns to become ready software developers for the real world and being someone who loves learning and spending time solving logical problems, it aligns with my personality and I hope to learn a whole lot from this journey.
HNG is a mission-driven company dedicated to working with top tech professionals to enhance their skills through our HNG internship program and expand their networks. Additionally, we collaborate with clients to connect them with the best technical talent worldwide. HNG offers programs tailored for intermediate to advanced learners aiming to accelerate their careers and secure positions at top international companies.
It is program every go-getter developer of tech personality should participate in.