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]

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. For latest updates and blogs, follow us on Twitter. 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. Check out my other blog, Revive-n-Thrive.com

Share
Published by
Ajitesh Kumar

Recent Posts

Feature Engineering in Machine Learning: Python Examples

Last updated: 3rd May, 2024 Have you ever wondered why some machine learning models perform…

7 hours ago

Feature Selection vs Feature Extraction: Machine Learning

Last updated: 2nd May, 2024 The success of machine learning models often depends on the…

1 day ago

Model Selection by Evaluating Bias & Variance: Example

When working on a machine learning project, one of the key challenges faced by data…

1 day ago

Bias-Variance Trade-off in Machine Learning: Examples

Last updated: 1st May, 2024 The bias-variance trade-off is a fundamental concept in machine learning…

2 days ago

Mean Squared Error vs Cross Entropy Loss Function

Last updated: 1st May, 2024 As a data scientist, understanding the nuances of various cost…

2 days ago

Cross Entropy Loss Explained with Python Examples

Last updated: 1st May, 2024 In this post, you will learn the concepts related to…

2 days ago