Categories: Web

Web Application Folder Structure for Spring MVC Web Projects

The article lists down two most commonly used folder structure for a Spring MVC/Hibernate based web application project. In fact, this folder structure could be used with any other MVC framework like Spring. Following are different two folder structures described later in this article:

  • Eclipse-based Web Application (Dynamic Web Project)
  • Maven-based Web Application Project
Eclipse-based Web Application (Dynamic Web Project)

As per this Eclipse page, Dynamic web projects contain dynamic Java EE resources such as servlets, JSP files, filters, and associated metadata, in addition to static resources such as images and HTML files. Following is how the folder structure looks like on the disk:

  • src
    • packages (com.orgid.abc)
  • WebContent
    • CSS/JS Folders (Publicly accessible; DO NOT Put them within WEB-INF)
    • META-INF (Manifest.mf)
    • WEB-INF
      • lib (Consists of Spring, Hibernate and dependent libraries)
      • views (depends upon the configuration in spring-servlet.xml)
      • web.xml
      • spring-servlet.xml (Spring related configuration)
      • hibernate.cfg.xml (Hibernate related configuration)

Following is the sample screenshot of how it looks within Eclipse:

Maven-based Web Application Project

Following is the standard folder structure one would find in many of the web applications. It is  also the directory layout expected by Maven and the directory layout created by Maven. The details about this folder structure could be found on the Maven Apache page. The directory structure is primarily laid down based on two code groupings:

  • src/main: Main build artifact consisting of Java code, configuration files, filters, scripts, application libraries etc. All these artifacts are placed within “src/main” and sub-folders as java, webapp, resources, filters, configs, scripts. It looks like following:”
  • src/test: Test build artifact consisting of unit test code. The unit tests code is placed within folder such as “src/test/java”.

Following is the minimum folder structure based on above description that would be enough to run your hello world Spring MVC/Hibernate application:

  • src/main/java: Consists of source code
  • src/main/webapp: Consists of libraries, configuration files, resources etc.
    • CSS/JS Folders (Publicly accessible; DO NOT put them within WEB-INF)
    • META-INF (Manifest.mf)
    • WEB-INF
      • lib  (Consists of Spring, Hibernate and dependent libraries)
      • views (Depends upon the configuration in spring-servlet.xml)
      • web.xml
      • spring-servlet.xml (Spring related configuration)
      • hibernate.cfg.xml (Hibernate related configuration)
  • src/test/java: Consists of unit test code

If you are working on Maven based project, you could adopt the Maven-based folder structure. Build tools such as Gradle work like charm. However, Gradle could easily be configured to work with Eclipse-based dynamic web project folder structure. This will be discussed in later articles. Rookies could start with Eclipse-based folder structure.

[adsenseyu1]

Latest posts by Ajitesh Kumar (see all)
Ajitesh Kumar

I have been recently working in the area of Data analytics including Data Science and Machine Learning / Deep Learning. I am also passionate about different technologies including programming languages such as Java/JEE, Javascript, Python, R, Julia, etc, and technologies such as Blockchain, mobile computing, cloud-native technologies, application security, cloud computing platforms, big data, etc. I would love to connect with you on Linkedin. Check out my latest book titled as First Principles Thinking: Building winning products using first principles thinking.

Share
Published by
Ajitesh Kumar

Recent Posts

What are AI Agents? How do they work?

Artificial Intelligence (AI) agents have started becoming an integral part of our lives. Imagine asking…

2 weeks ago

Agentic AI Design Patterns Examples

In the ever-evolving landscape of agentic AI workflows and applications, understanding and leveraging design patterns…

2 weeks ago

List of Agentic AI Resources, Papers, Courses

In this blog, I aim to provide a comprehensive list of valuable resources for learning…

2 weeks ago

Understanding FAR, FRR, and EER in Auth Systems

Have you ever wondered how systems determine whether to grant or deny access, and how…

3 weeks ago

Top 10 Gartner Technology Trends for 2025

What revolutionary technologies and industries will define the future of business in 2025? As we…

3 weeks ago

OpenAI GPT Models in 2024: What’s in it for Data Scientists

For data scientists and machine learning researchers, 2024 has been a landmark year in AI…

3 weeks ago