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. 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

Agentic Reasoning Design Patterns in AI: Examples

In recent years, artificial intelligence (AI) has evolved to include more sophisticated and capable agents,…

3 weeks ago

LLMs for Adaptive Learning & Personalized Education

Adaptive learning helps in tailoring learning experiences to fit the unique needs of each student.…

4 weeks ago

Sparse Mixture of Experts (MoE) Models: Examples

With the increasing demand for more powerful machine learning (ML) systems that can handle diverse…

1 month ago

Anxiety Disorder Detection & Machine Learning Techniques

Anxiety is a common mental health condition that affects millions of people around the world.…

1 month ago

Confounder Features & Machine Learning Models: Examples

In machine learning, confounder features or variables can significantly affect the accuracy and validity of…

1 month ago

Credit Card Fraud Detection & Machine Learning

Last updated: 26 Sept, 2024 Credit card fraud detection is a major concern for credit…

1 month ago