Skip to main content

How to deploy the Spring Boot application ( jar/war ) on the live server?


There are various methods to deploy the Spring Boot application. In the previous page, we have described how to generate builds (jar/war) by Maven/Gradle. In this article, we will describe the built deployment process.

So before we begin deploying spring boot applications that are built in either jar or war, we need to understand what are the differences between them, both can be built using any of the built tools Gradle and Maven.

What are the differences between jar and war?

jar (Java ARchive) war ( Web Application Resource)
JAR stands for Java ARchive. WAR  stands for Web Application Resource, also stated Web application ARchive.
It is used to aggregate many Java class files and associated metadata and resources (text, images, etc.) into one file The war contains only binaries and resources that are required for web application

The jar is a self-executable binary archive with an embedded tomcat server.

It needs a pre-configured servlet container that runs a java web application either of Tomcat, Glassfish Server.

How to generate builts jar or war in spring boot?

When we create a project from the spring initializr, there is an option to select Packaging type Jar or War, decide what you need according to your requirement, and choose the needed one.

The application builds are the archive of the binaries compiled source code. Let us know what is needed and how to deploy each archive one by one:

Deploying a JAR (Java Archive) as a standalone application

The jar is a self-executable binary archive with an embedded tomcat server.

If you want to deploy it in Windows OS, you can just double click on it, it will be deployed automatically on the port number you mentioned in the application properties file if not then default port 8080

If you deploy it with Command Line Interface (CLI) in windows cmd and in Linux/Mac Terminal then you can have various deployment options to change configuration externally from the jar like you can mention port number, profile (development/ testing/ production) and many other options.

Command:

$ java -jar filepath/filename.jar

$ java -Dserver.port=8084 -jar filepath/filename.jar  // to run on custom port

$ java -Dspring.profiles.active=testing -jar filepath/filename.jar
// to run with a particular profile

Click here To learn more about externalized configurations.

Deploying a WAR (Web Application Archive) into a servlet container

This archive contains only the web application binaries. It needs a pre-configured servlet container that runs java web application either of Tomcat, Glassfish server.

Taking example of Tomcat server, Inside the directory of the tomcat you can find directories like bin/ conf/ logs/ webapps/ lib/ temp/ work/ etc.

All you just need to move your war file into the webapps/ directory, delete the directory if already present inside webapps/ with the same name as your war file and restart the tomcat server it will deploy automatically in few seconds

Your war file should be named ROOT.war so that you can access directly http://localhost:8080 . If not then you have to type the name as your war filename after the application root. e.g if your filename is demo.war then the access URL will be http://localhost:8080/demo

Thus, it enables us to deploy multiple applications into the same servlet container.

Popular posts from this blog

How to Implement AWS RDS Database IAM Authentication in Spring Boot

Amazon RDS for MySQL allows authentication using AWS Identity and Access Management (IAM) database authentication. With this authentication method, you don't need to use a password when you connect to a DB instance. Instead, you use an authentication token. Let us understand how this works? An authentication token is a unique string of characters that Amazon RDS generates on request. Authentication tokens are generated using AWS Signature Version 4. Each token has a lifetime of 15 minutes. You don't need to store user credentials in the database, because authentication is managed externally using IAM. You can also still use standard database authentication. Since IAM authentication tokens are short-lived access tokens that are valid for 15 minutes. For the RDS database this token works as a database password that is required to establish a connection and does not determine how long the existing connection can last. The default value for connection to be alive without activit...

What Is SSL Certificate and how it works?

Deep Dive into SSL Certificate What Is an SSL Certificate? SSL (Secure Sockets Layer) is the common name for TLS (Transport Layer Security), a security protocol that enables encrypted communications between two machines. An SSL certificate is a small data file leveraging this security protocol to serve two functions: Authentication – SSL certificates serve as credentials to authenticate the identity of a website. They are issued to a specific domain name and web server after a Certificate Authority, also known as a Certification Authority (CA), performs a strict vetting process on the organization requesting the certificate. Depending on the certificate type, it can provide information about a business or website's identity and authenticate that the website is a legitimate business. Secure data communication - When SSL is installed on a web server, it enables the padlock to appear in the web browser. It activates the HTTPS protocol and creates a secure connection between th...

How to upload files in Amazon S3 Bucket using Spring Boot

As stated in the title, we are going to demonstrate that how we can upload and retrieve files from the amazon s3 bucket in spring boot. For this, we must have an account on amazon web services (AWS) . And the next thing you need to have is an IAM user that has programmatic access to the s3 bucket. Follow the steps below to create an IAM user and s3 bucket. Table of Contents 1. Steps to create an IAM user in AWS with S3 bucket full access permission Step 1.1 Login to your AWS account   Step 1.2 Set the user details Step 1.3 Set user permissions Step 1.4 Create a user group and set the access policy Step 1.5 Add user to the group Step 1.6  Set the tags (optional) Step 1.7  Review the user details and permission summary Step 1.8 Download the user credentials 2. See, how to create s3 bucket. Step 2.1 Click on the "Create bucket" button. Step 2.2 Enter the bucket name and select bucket region. Step 2.3 Set file accessibility for bucket items as publi...

How to Implement Spring Security in Spring Boot

Security Example in Spring Boot Implementation of Spring Security in the Spring Boot application is the key point to learn for spring boot developers. Because Authentication and Authorization are the backbones of the whole application. Getting started with the Spring Security Series, this is the first part, in this article we are going to focus on the authentication part with minimal registration. The implementation of registration flow with email verification, customizing password encoding, and setting up password strengths and rules will be explored in another separate article for each.  This article will be the base of the spring security series, the other security features will be explained on the basis of this implementation, so be focused and let's understand. The code contains proper naming & brief comments that makes it very comprehensive. If you feel any difficulty or find any issue, please drop a comment below this post The main goal of this article is to impleme...

Understanding - Spring Initializr

The Spring Initializr is ultimately a web application that generates a Spring Boot project structure for you. It can be used from different interfaces. From Web-based interface ( https://start.spring.io or https://start-scs.cfapps.io ) From supported IDE s STS , Eclipse , Netbeans , Intellij Idea . In the case of Eclipse, you need to install a plugin 'STS'. From CLI (Command Line Interface) Web-Based UI  (the same interface is opened in supported IDEs )   Project: Maven or Gradle          This is the selection of the project built tool or Dependency Manager that is used to manage all the dependencies added in the projects and to compile and pack the project in selected packaging ( jar or war ). If you want to know more about the selection of built tool and comparison between Maven and Gradle click the below link. What to choose Maven or Gradle?   Language: This section will is used to select the language in which you are comfortabl...

Custom Pagination with search and filters in Spring Boot

Every spring boot application is made to manage a large set of data. Also, we need to perform a search and filter the data according to need, And also we cannot load all data in one go on a single page so we need pagination too. In this article, we are going to demonstrate custom pagination with search and filter performed through ajax call. Goal: This demonstration is performed on a set of students' data. We have written a method to generate sample data.   Table of Contents 1. Initialize the project with the following dependencies 2. Set the application properties 3. Create the Student entity 4. Enum to denote the class of student 5. Create JPA repository of entity 6. Create the search & filter command object (CO) 7. Create a data transfer object (DTO) of the Entity for returning the response 8. Create a service for implementing the business login 9. Create a controller 10. Create a utility class for date conversions 11. Create the HTML Data Table design 12. ...