Posts

Spring Boot Maven Plugin Explained In Detail

Maven is a build automation tool for Java. The Spring Boot Maven plugin provides various capabilities for developing/executing Spring Boot projects with Maven. In this article, we will take a closer look at this plugin. What is the Spring Boot Maven Plugin The Spring Boot Maven plugin simplifies the process of building, packaging, and running Spring Boot applications using Maven.  Some of the things that you can do using this plugin are: Build/package Spring Boot applications as executable JAR or WAR files. These files include all necessary dependencies, making it easy to deploy and run Spring Boot applications. Start an embedded application server (such as Tomcat or Jetty) and deploy your Spring Boot application on it during development and testing. Manage and resolve dependencies specific to Spring Boot, ensuring that you have compatible versions of Spring Boot libraries and other related dependencies. Simplify configuration management by setting Spring Boot properties directly in yo

Maven clean install command explained

Maven is a popular build automation and project management tool primarily used for Java projects. Java developers often run the maven clean install command to build Java projects. In this blog post, I will try to explain what the maven clean install command does. Let us break down this command.   Clean This part of the command tells Maven to clean the project. Cleaning a project means removing all the build artifacts (compiled classes, libraries, generated files, etc.) from previous builds. This ensures that you start with a clean slate before building the project again. It’s particularly useful to eliminate any potential issues caused by leftover artifacts from previous builds.   Install   This part of the command tells Maven to build and package the project and then install the resulting artifact(s) into the local Maven repository. The local repository is a local cache where Maven stores project dependencies and artifacts. When you use “install,” the project’s packaged artifact (e.g

How to create a Jar file from a Spring Boot Application using Maven

In this article, we will learn how to create a JAR file from a Spring Boot application using Maven. Introduction The spring-boot-maven-plugin allows packaging a Spring Boot application as a JAR/WAR file. It needs to be specified in the project  pom.xml along with the type of packaging ( jar / war ). Project Creation and Setup Step 1 – Let us use an existing project as a starting point. Clone the code from this Spring Boot Thymeleaf project. Step 2 – Update the pom.xml to specify the packaging and the `spring-boot-maven-plugin` configuration. So the pom file should look as follows: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.learnjava</groupId> <artifactId>learnjava-springbootthymeleaf-demo</artifactId>

New Features in Java 11 Explained in Detail

Java 11, is the latest long-term support (LTS) version of the Java programming language. It brings along several exciting features and improvements. In this blog post, we’ll take high level look into the New Features in Java 11. Local Variable Syntax for Lambda Parameters One of the most important features in Java 11 is the ability to use the var keyword for lambda parameters. This allows for more concise and readable code when working with lambda expressions. Java 10 introduced the Local Variable Type Inference feature . However, the var keyword could not be used with lambda expressions. So, you would need to write a lambda expression as follows: (int a, int b) -> a + b This code can be rewritten in Java 11 as follows: (var a, var b) -> a + b   HTTP Client Improvements Java 11 introduces a new and modern HTTP client API that supports HTTP/1.1, HTTP/2, and WebSocket. This new client offers a more flexible and efficient way to make HTTP requests and process responses. It’s fully

Introduction to Docker to get you started

On a recent project, I got an opportunity to work with Docker. In this article, I will be giving an introduction to Docker and explaining some basic Docker concepts. What is Docker? Docker is a container service that helps developers quickly package and run an application in any environment. It addresses the one problem that every developer has faced at least once in her life, “It works on my machine!” For example, suppose there are multiple developers working in different environments like Linux/Windows and MacOS. Docker makes it easy to move the complete application setup from one environment to the other. Suppose the application being worked on is a Java application that requires different pieces of software like a web container like Tomcat, a database like MySQL, and so on. Without Docker, you would need to individually install each software in order to set up the development environment on a different machine. Not only that, but when you move from development to test/production, y

How to use logging in SpringBoot with code samples

Image
In this article, we will learn how to use logging in SpringBoot. Introduction There are several Java logging frameworks like logback, log4j, and so on. Spring Boot supports out-of-the-box support for logback. Let us learn how to use logging in SpringBoot with logback. Step 1 – Create a New Maven Project Create a new Maven project. (Refer to  this  blog post). This will create a project in Eclipse as follows:   Step 2 – Add the Spring Boot Dependencies Add the spring-boot-starter-web dependency to the pom.xml . So, the pom.xml should look as follows: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.learnjava</groupId> <artifactId>learnjava-springboot-logging-example</artifactId> <version>0.0.1-SNAPSHOT&

How to create a Maven web project using archetype selection

Image
In my earlier article, we learned how to create a Java web project in Eclipse and how to add Maven support to it.  In this article, we will learn how to create a Maven web project using archetype selection. Create Maven Web Project In Eclipse Step 1 – In Eclipse, Click on File > New > Other . Click on Maven Project . Click Next : Step 2 – The following screen is displayed. Click Next : Step 3 – In the Filter text box, type “ maven-archetype-webapp “.  Select “ org.apache.maven.archetypes “. Click Next : Step 4 – Enter Group Id and Artifact Id . Click Finish : This creates a web project with the required directory structure: Now you can add the necessary dependencies to your pom file as explained in this post. So for example, if you are creating a Spring application, you can add Spring dependencies. You can also use this as a template to create any web application with Maven support. Further Learning Apache Maven Beginner to Guru Maven Crash Course Java Programming in Eclips