0% found this document useful (0 votes)
25 views

#1 FoundationEnterpriseProgramming

Uploaded by

Harsh Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

#1 FoundationEnterpriseProgramming

Uploaded by

Harsh Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Foundation of Enterprise Programming

The "Foundation of Enterprise Programming in Java" refers to the fundamental concepts, tools,
and technologies used to build robust, scalable, and maintainable enterprise-level applications
using the Java programming language.
Java Enterprise Programming, also known as Java EE (Enterprise Edition), is a robust, scalable,
and multi-tiered platform designed to build and run enterprise-level applications. The platform
is built on top of Java SE (Standard Edition) and provides a set of specifications and guidelines
that extend the capabilities of Java to support large-scale, distributed, and transaction-oriented
applications.

Here's an overview of the key components involved:


1. Core Java Concepts
➢ Object-Oriented Programming (OOP): Understanding classes, objects, inheritance,
polymorphism, encapsulation, and abstraction.
➢ Java Standard Edition (Java SE): Core libraries and features such as collections,
input/output (I/O), exception handling, multithreading, and networking.
2. Java Enterprise Edition (Java EE) / Jakarta EE
➢ Servlets and JSP: Building web applications using Java Servlets and JavaServer Pages.
➢ Enterprise JavaBeans (EJB): Server-side components that encapsulate business logic.
➢ Java Persistence API (JPA): Managing relational data in Java applications using Object-
Relational Mapping (ORM).
➢ Java Message Service (JMS): Enabling messaging between distributed systems.
➢ Java Transaction API (JTA): Managing transactions across multiple resources.
3. Frameworks and Tools
➢ Spring Framework: A comprehensive framework that provides support for dependency
injection, aspect-oriented programming, transaction management, and more. Key
components include Spring Boot for rapid application development, Spring MVC for web
applications, and Spring Data for database access.
➢ Hibernate Framework: A popular ORM framework that simplifies database interactions
using JPA.
➢ Spring Boot Framework: A module of the Spring Framework that simplifies the
development of new Spring applications by providing defaults for configuration and a
powerful suite of tools. It is designed to get applications up and running quickly with
minimal configuration.
➢ Spring MVC: A part of the Spring Framework used to build web applications following
the Model-View-Controller (MVC) pattern.
➢ Spring Data: Simplifies data access, significantly reducing the amount of boilerplate
code needed to implement data access layers.
4. Web Services
➢ RESTful Web Services: Building and consuming REST APIs using JAX-RS (Java API for
RESTful Web Services).
➢ SOAP Web Services: Using JAX-WS (Java API for XML Web Services) to build and
consume SOAP-based services.
5. Security
➢ Java Authentication and Authorization Service (JAAS): Implementing security features
such as authentication and authorization.
➢ Spring Security: A powerful framework for securing enterprise applications.
6. Enterprise Integration
➢ Enterprise Integration Patterns (EIP): Using patterns for integrating enterprise
applications, often facilitated by frameworks like Apache Camel.
➢ Microservices: Designing and building microservice architectures using Spring Boot and
Spring Cloud.
7. Testing
➢ JUnit: A widely used testing framework for unit testing Java applications.
➢ Mockito: A framework for mocking objects in unit tests.
8. Build and Deployment Tools
➢ Maven: A build automation tool that manages project dependencies and builds
processes.
➢ Gradle: Another build automation tool that offers flexibility and performance
improvements over Maven.
➢ Continuous Integration/Continuous Deployment (CI/CD): Using tools like Jenkins for
automated build and deployment pipelines.
9. Cloud and Containerization
➢ Docker: Containerizing applications for consistency across development and production
environments.
➢ Kubernetes: Orchestrating and managing containerized applications.
➢ Cloud Platforms: Deploying Java applications on cloud platforms such as AWS, Google
Cloud, and Azure.
10. Best Practices and Design Patterns
➢ Design Patterns: Leveraging common design patterns such as Singleton, Factory, and
Observer to solve recurring problems.
➢ Best Practices: Writing clean, maintainable, and efficient code, following coding
standards, and conducting code reviews.
11. Monitoring and Logging
➢ SLF4J and Logback/Log4j: Implementing logging in Java applications.
➢ Monitoring Tools: Using tools like Prometheus and Grafana for monitoring application
performance.

Significance of Java EE
Scalability:
Java EE is designed to support highly scalable applications. It can handle a large number of
concurrent users and transactions, making it ideal for enterprise-level applications.
Security:
Java EE provides comprehensive security features, including authentication, authorization, and
secure communication. These features help protect sensitive enterprise data and transactions.
Portability:
Applications developed using Java EE can run on any compliant Java EE application server,
providing flexibility and reducing vendor lock-in.
Integration:
Java EE includes APIs and tools for integrating with various enterprise systems, databases, and
other technologies. This makes it easier to build applications that interact with existing
enterprise infrastructure.
Productivity:
Java EE offers a wide range of pre-built components and services that simplify application
development. This allows developers to focus on business logic rather than boilerplate code.
Community and Support:
Java EE has a large and active community of developers and organizations contributing to its
development. There is extensive documentation, support, and a wealth of libraries and
frameworks available.
Robustness and Reliability:
Java EE's mature platform has been proven in countless enterprise environments. It provides
robust transaction management and fault tolerance, ensuring high reliability and uptime for
mission-critical applications.

What is XML?
XML (eXtensible Markup Language) is a versatile and widely-used format for structuring,
storing, and transporting data. It is a markup language much like HTML but designed to carry
data rather than display it.
Key Characteristics of XML
➢ Self-Descriptive: XML uses tags to describe data, making it readable by both humans
and machines.
➢ Hierarchical Structure: XML documents are structured as a tree of elements, with each
element potentially containing child elements, attributes, and data.
➢ Platform-Independent: XML is platform-independent and language-agnostic, meaning it
can be used across different systems and programming languages.
➢ Extensible: Users can create their own tags and define their structure, making XML
highly flexible.
Basic Structure of XML
An XML document consists of elements enclosed in tags. Here is a simple example:
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book category="fiction">
<title lang="en">Harry Potter</title>
<author>J.K. Rowling</author>
<year>1997</year>
<price>29.99</price>
</book>
<book category="programming">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>

Key Components of XML


➢ Declaration: The <?xml version="1.0" encoding="UTF-8"?> line at the top of the
document is the XML declaration, specifying the XML version and character encoding.
➢ Elements: Defined by opening and closing tags (e.g., <book> and </book>). Elements
can contain other elements, text, or attributes.
➢ Attributes: Provide additional information about elements. For example, <book
category="fiction"> includes an attribute category with the value "fiction".
➢ Text Content: The data within an element (e.g., Harry Potter within the <title> element).
➢ Root Element: The single top-level element that contains all other elements. In this
example, <bookstore> is the root element.
XML Syntax Rules
➢ Tags are Case-Sensitive: <Book> and <book> are different.
➢ Elements Must be Properly Nested: Each opening tag must have a corresponding closing
tag, and tags must be correctly nested.
<outer><inner></inner></outer> <!-- Correct -->
<outer><inner></outer></inner> <!-- Incorrect -->
➢ Attribute Values Must be Quoted: Attribute values should be enclosed in quotes (single
or double).
<element attribute="value"></element>
➢ Well-Formed Documents: An XML document must be well-formed, meaning it follows
all the syntax rules.
Uses of XML
➢ Data Storage: XML can be used to store data in a structured format.
➢ Data Exchange: XML is often used to exchange data between different systems,
especially in web services and APIs.
➢ Configuration Files: Many applications use XML for configuration files (e.g., Spring
configuration files in Java).
➢ Document Representation: XML is used in various document formats like DOCX, which
is essentially a collection of XML files.
Java provides several APIs for working with XML, such as:
➢ DOM (Document Object Model): Allows for reading and manipulating XML as a tree
structure.
➢ SAX (Simple API for XML): An event-driven, stream-based API for parsing XML.
➢ StAX (Streaming API for XML): A pull-parsing API for reading and writing XML.
➢ JAXB (Java Architecture for XML Binding): Provides a way to map Java objects to XML
representations and vice versa.

Here is a simple example of how to parse an XML file using the DOM parser in Java:
https://github.com/anirudhagaikwad/Servlet_SpringBoot/tree/master/Practicals/XML_Demo
This program reads an XML file, parses it, and prints the details of each book.

Design Patterns
Design patterns are reusable solutions to common problems that occur in software design. They
represent best practices refined over time and provide a template for solving issues in a
standardized way. Each pattern is like a blueprint that can be used in various situations,
enabling developers to build more efficient and maintainable software.

Categories of Design Patterns


1. Creational Patterns:
➢ Focus on object creation mechanisms, trying to create objects in a manner suitable to
the situation.
Examples:
➢ Singleton: Ensures a class has only one instance and provides a global point of access to
it.
➢ Factory Method: Defines an interface for creating an object but lets subclasses alter the
type of objects that will be created.
➢ Abstract Factory: Provides an interface for creating families of related or dependent
objects without specifying their concrete classes.
➢ Builder: Separates the construction of a complex object from its representation,
allowing the same construction process to create different representations.
➢ Prototype: Creates new objects by copying an existing object, known as the prototype.

2. Structural Patterns:
➢ Deal with object composition or structure and ensure that if one part of a system
changes, the entire system doesn’t need to change.
Examples:
➢ Adapter: Allows incompatible interfaces to work together.
➢ Decorator: Adds behavior or responsibilities to objects dynamically.
➢ Facade: Provides a simplified interface to a complex subsystem.
➢ Proxy: Provides a surrogate or placeholder for another object to control access to it.
➢ Composite: Composes objects into tree structures to represent part-whole hierarchies.

3. Behavioral Patterns:
➢ Concerned with algorithms and the assignment of responsibilities between objects.
Examples:
➢ Observer: Defines a one-to-many dependency between objects so that when one object
changes state, all its dependents are notified and updated automatically.
➢ Strategy: Defines a family of algorithms, encapsulates each one, and makes them
interchangeable.
➢ Command: Encapsulates a request as an object, thereby allowing for parameterization
of clients with queues, requests, and operations.
➢ Chain of Responsibility: Passes a request along a chain of handlers until an object
handles it.
➢ Mediator: Defines an object that encapsulates how a set of objects interact, promoting
loose coupling.

Importance of Design Patterns in Enterprise Programming


1. Reusability:
➢ Patterns provide proven solutions that can be reused in different parts of an application
or in different projects, saving time and effort.
2. Standardization:
➢ Using well-known patterns makes code more readable and understandable for
developers familiar with the pattern, promoting better communication and
collaboration within teams.
3. Maintainability:
➢ Patterns help in creating code that is easier to maintain and extend. By following
established design principles, the codebase becomes more structured and less prone to
errors.
4. Scalability:
➢ Many design patterns, such as Singleton or Factory, are geared towards creating scalable
systems that can handle growth without significant refactoring.
5. Flexibility and Extensibility:
➢ Patterns like Strategy and Decorator allow for the flexible addition of new functionalities
and behaviors without modifying existing code, adhering to the Open/Closed Principle.
6. Separation of Concerns:
➢ Patterns like MVC (Model-View-Controller) enforce separation of concerns, ensuring
that different parts of the application (data, business logic, and user interface) are
decoupled from each other, leading to a cleaner and more organized codebase.
7. Reduction of Complexity:
➢ By abstracting complex interactions into simpler, more manageable components,
patterns help reduce the overall complexity of the system. Facade and Mediator
patterns are excellent examples of this.
8. Best Practices:
➢ Patterns encapsulate best practices and strategies that have been honed over time.
Adopting these can improve the overall quality and robustness of the application.
9. Adaptability:
➢ In an ever-changing technological landscape, patterns help in creating systems that can
adapt to new requirements or changes with minimal impact. Adapter and Proxy
patterns are useful in integrating new systems or components.
Introduction to JDBC
Java Database Connectivity (JDBC) is an API (Application Programming Interface) that allows
Java applications to interact with databases. It provides methods to query and update data in
a database, and is designed to be database-independent.
JDBC Architecture
The JDBC architecture consists of two layers:
1) The JDBC API provides a standard interface for Java applications to interact with
databases, offering classes and interfaces for database operations.
2) The JDBC Driver API acts as a bridge between the JDBC API and specific database
systems, defining interfaces and classes that JDBC drivers must implement for
database connectivity.
Together, these layers enable Java applications to communicate with various database
systems in a consistent and standardized manner, facilitating database operations and data
retrieval.
Components of JDBC

Component Type Description Example Usage

Manages the set of JDBC drivers. It is used


to establish a connection to the database by Connection conn =
DriverManager Class DriverManager.getConnection(url, user,
selecting the appropriate driver from the set password);
of registered JDBC drivers.

Represents a connection to a specific


database. Provides methods for creating Connection conn =
Connection Interface DriverManager.getConnection(url, user,
statements, managing transactions, and password);
closing the connection.

Used to execute static SQL statements and


return the results produced by those Statement stmt = conn.createStatement();
Statement Interface ResultSet rs = stmt.executeQuery("SELECT
statements. Ideal for simple SQL queries * FROM table_name");
without parameters.
A precompiled SQL statement which can be
executed multiple times with different input PreparedStatement pstmt =
conn.prepareStatement("SELECT * FROM
PreparedStatement Interface parameters. Helps prevent SQL injection table_name WHERE id = ?"); pstmt.setInt(1,
attacks and improves performance for 1); ResultSet rs = pstmt.executeQuery();
repetitive queries.
Represents the result set of a query
executed using a Statement or ResultSet rs = stmt.executeQuery("SELECT
* FROM table_name"); while (rs.next()) { int
ResultSet Interface PreparedStatement. Provides methods to
id = rs.getInt("id"); String name =
navigate and retrieve data from the result rs.getString("name"); // process the row }
set.

Provides information on a database access try { Connection conn =


error or other errors. It is thrown by most DriverManager.getConnection(url, user,
SQLException Class methods in the java.sql package and includes password); // Other database operations }
details about the error, such as SQL state, catch (SQLException e) {
error code, and a descriptive message. e.printStackTrace(); }

Refer Practical from Github Repository


https://github.com/anirudhagaikwad/Servlet_SpringBoot/blob/master/Practicals/JDBC_Exa
mple/src/practical/JDBC_CURD.java
https://github.com/anirudhagaikwad/Servlet_SpringBoot/blob/master/Practicals/JDBC_Exa
mple/src/practical/JDBC_Demo2.java
JDBC Drivers and Their Usage
JDBC drivers are required to connect to the database. There are four types of JDBC drivers:

Driver Type Description Pros Cons


Uses ODBC drivers
to connect to the Performance overhead, platform
Quick setup, ODBC
Type-1 (JDBC-ODBC Bridge) database. Converts dependency, deprecated in Java 8,
compatibility
JDBC calls into removed in Java 9
ODBC calls.
Uses client-side
libraries of the
database. Converts Better performance, Platform dependency, maintenance
Type-2 (Native-API Driver)
JDBC calls into database-specific features overhead
database-specific
calls.
Uses a middleware
server to convert
Type-3 (Network Protocol
JDBC calls into High portability, scalability Complex setup, potential bottleneck
Driver)
database-specific
calls.
Directly converts
JDBC calls into
High performance, platform
Type-4 (Thin Driver) database-specific Database-specific, limited features
independence, simplicity
calls. Pure Java
driver.
RowSet interface
The `RowSet` interface in Java is a part of the Java Database Connectivity (JDBC) API and provides a
more flexible and easier-to-use alternative to the traditional `ResultSet` interface. A `RowSet` object
contains a set of rows from a relational database and can be used to interact with these rows both
while connected to a database and while disconnected.

Key Features of RowSet


1. Flexibility: `RowSet` can operate in both connected and disconnected modes.
2. Scrollable: `RowSet` objects are scrollable, meaning you can move the cursor both forward
and backward.
3. Updatable: `RowSet` objects can be updated, allowing changes to the database.
4. Event Notification: `RowSet` supports event listeners, which can be notified when certain
events occur (e.g., a row is inserted, updated, or deleted).

Types of RowSet
Java provides several types of `RowSet` implementations, each designed for different use cases:
1. JdbcRowSet
2. CachedRowSet
3. WebRowSet
4. FilteredRowSet
5. JoinRowSet

1. JdbcRowSet
➢ Description: `JdbcRowSet` is a connected `RowSet` that maintains a constant connection
to the database using JDBC.
➢ Use Case: It is used when you need real-time access to the database and want to operate
in a connected mode.
2. CachedRowSet
➢ Description: `CachedRowSet` is a disconnected `RowSet` that caches its data in memory.
It can be populated with data from a `ResultSet` and later used while disconnected from
the database.
➢ Use Case: It is useful for applications that need to manipulate data offline and later
synchronize changes with the database.
3. WebRowSet
➢ Description: `WebRowSet` extends `CachedRowSet` and adds the capability to read and
write data in XML format. This makes it easy to transfer data over the web.
➢ Use Case: It is used for transferring tabular data between different components of a web
application or between different web services.
4. FilteredRowSet
➢ Description: `FilteredRowSet` extends `CachedRowSet` and allows the filtering of rows
based on a filtering criteria. It implements the `Predicate` interface to define custom
filtering logic.
➢ Use Case: It is useful for applications that need to process a subset of data based on
specific conditions.
5. JoinRowSet
➢ Description: `JoinRowSet` allows the joining of data from multiple `RowSet` objects. It
can be used to perform SQL-like joins between different `RowSet` instances.
➢ Use Case: It is useful for combining data from different sources without needing a direct
database join operation.

Refer Practical from Github Repository


https://github.com/anirudhagaikwad/Servlet_SpringBoot/blob/master/Practicals/J
DBC_Example/src/practical/RowSetDemo.java
What is a Build Automation Tool?

A build automation tool is software designed to automate the process of compiling source code
into binary code, packaging the binaries, running tests, and deploying applications. It
streamlines and standardizes the build process, reducing the need for manual intervention and
minimizing errors. Build automation tools are essential in modern software development for
ensuring consistent, repeatable, and efficient builds.

Why Use Build Automation Tools?


1. Efficiency:
➢ Automates repetitive tasks, freeing up developers to focus on coding and problem-
solving.
2. Consistency:
➢ Ensures that builds are consistent and reproducible, reducing discrepancies between
different development environments.
3. Error Reduction:
➢ Minimizes the risk of human errors by automating complex and repetitive build steps.

4. Continuous Integration and Deployment (CI/CD):


➢ Facilitates CI/CD practices by automating the integration, testing, and deployment
processes.
5. Dependency Management:
➢ Automatically handles dependencies, ensuring that all necessary libraries and
frameworks are included in the build.
6. Testing and Quality Assurance:
➢ Integrates with testing frameworks to automate unit, integration, and functional
testing, ensuring code quality.
7. Scalability:
➢ Supports building and deploying projects across multiple platforms and environments.
Types of Build Automation Tools
There are several types of build automation tools, each designed to cater to different aspects
of the build process. The primary types include:
1. Build Systems:
- Tools that automate the compilation of source code, linking of binaries, and other build
tasks.
2. Package Managers:
- Tools that handle the downloading, installation, and management of software
dependencies.
3. Continuous Integration Tools:
- Tools that automate the integration and testing of code changes, often integrating with
version control systems.

Examples of Build Automation Tools


1. Build Systems:
1) Apache Maven:
➢ A build automation tool primarily for Java projects, using `pom.xml` for configuration.
➢ Manages project dependencies and supports plugins for various build tasks.
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.3.6</version>
</dependency>
2)Gradle:
➢ A flexible build automation tool that supports multiple languages and uses a Groovy or
Kotlin-based DSL (Domain Specific Language) for configuration.
3) Apache Ant:
➢ An older build tool that uses XML for configuration (`build.xml`). It's more manual
compared to Maven and Gradle.

2. Package Managers:
1) npm (Node Package Manager):
➢ Used for managing JavaScript dependencies in Node.js projects. Configured using
`package.json`.
2) pip:
➢ A package manager for Python, managing libraries and dependencies. Configured using
`requirements.txt`.
3) NuGet:
➢ A package manager for .NET, managing dependencies in .NET projects. Configured using
`packages.config` or `*.csproj` files.

3. Continuous Integration Tools:


1) Jenkins:
➢ An open-source automation server that supports building, deploying, and automating
projects. Configured using a web UI or `Jenkinsfile`.
2) Travis CI:
➢ A cloud-based CI service that integrates with GitHub. Configured using `.travis.yml`.
3) CircleCI:
➢ A CI/CD service that supports building, testing, and deploying applications. Configured
using `.circleci/config.yml`.
What is Maven?
Maven is a powerful project management and build automation tool used primarily for Java
projects. It simplifies the build process, dependency management, and project configuration,
making it easier to manage the lifecycle of a project. Maven uses a declarative approach, where
project structure and configuration are specified in a file called `pom.xml`.
Key Features of Maven:
1. Dependency Management:
➢ Automatically handles the downloading and inclusion of project dependencies (libraries
and plugins) from a central repository.
2. Build Automation:
➢ Provides a consistent way to build projects, including compiling code, packaging
binaries, running tests, and generating documentation.
3. Project Information:
➢ Provides project metadata and information through the `pom.xml` file.
4. Convention over Configuration:
➢ Promotes a standardized directory structure and build process, reducing the need for
detailed configuration.

5. Extensibility:
➢ Supports a wide range of plugins that extend its functionality, including plugins for
compiling code, running tests, generating reports, and more.
6. Lifecycle Management:
➢ Defines a standardized build lifecycle consisting of phases such as `validate`, `compile`,
`test`, `package`, `verify`, `install`, and `deploy`.
What is `pom.xml`?
`pom.xml` (Project Object Model) is the fundamental unit of configuration in Maven. It is an
XML file that contains information about the project and configuration details used by Maven
to build the project.
Key Sections of `pom.xml`:
1. Project Coordinates:
- Defines the unique identity of a Maven project.
<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
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>myapp</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
</project>

2. Dependencies:
➢ Specifies the libraries and frameworks required by the project. Maven automatically
downloads and includes these dependencies.

<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.3.6</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>

3. Build:
➢ Contains configuration for the build process, including plugins and resources.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.example.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>

4. Repositories:
➢ Specifies remote repositories to search for dependencies and plugins.
<repositories>
<repository>
<id>central</id>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
</repositories>

5. Properties:
➢ Defines custom properties that can be reused throughout the `pom.xml`.
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
6. Profiles:
➢ Allows different configurations for different environments (e.g., development, testing,
production).
<profiles>
<profile>
<id>development</id>
<properties>
<env>dev</env>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>production</id>
<properties>
<env>prod</env>
</properties>
</profile>
</profiles>
Example `pom.xml`
Here's a complete example of a simple `pom.xml`:

<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
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.example</groupId>
<artifactId>myapp</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>

<name>My Application</name>
<url>http://www.example.com/myapp</url>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.3.6</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.example.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>

You might also like