Categories
java spring spring-mvc

Standard project/package structure of a j2ee web application

We are starting a new Java EE web application using Spring, Sping MVC and Hibernate. We will most probably be using maven also.

Before starting we need to come up with the project/package structure for the web application.

What is the Standard project/package structure of a Java EE web application?

It should also run on all application servers without making any changes in the project structure or the any configuration files.

We will be using Spring source IDE version 2.6.0 (latest release).

Any ideas?

If you are using maven, it’s best to follow the standard maven project layout. You can get maven to generate this structure for you by doing,

mvn archetype:generate 

and select spring-mvc-jpa-archetype from the list of choices

This will give you a package structure like,

  ├── pom.xml
└── src
├── main
│   ├── java
│   │   └── mygroup
│   │   ├── controller
│   │   │   ├── HomeController.java
│   │   │   └── PersonController.java
│   │   ├── dao
│   │   │   └── PersonDao.java
│   │   └── model
│   │   └── Person.java
│   ├── resources
│   │   ├── db.properties
│   │   ├── log4j.xml
│   │   └── META-INF
│   │   └── persistence.xml
│   └── webapp
│   ├── index.html
│   ├── META-INF
│   │   ├── context.xml
│   │   └── MANIFEST.MF
│   ├── resources
│   │   └── css
│   │   └── screen.css
│   └── WEB-INF
│   ├── spring
│   │   ├── app
│   │   │   ├── controllers.xml
│   │   │   └── servlet-context.xml
│   │   ├── db.xml
│   │   └── root-context.xml
│   ├── views
│   │   ├── edit.jsp
│   │   ├── home.jsp
│   │   └── list.jsp
│   └── web.xml
└── test
├── java
│   └── mygroup
│   ├── controller
│   │   ├── DataInitializer.java
│   │   ├── HomeControllerTest.java
│   │   └── PersonControllerTest.java
│   └── dao
│   └── PersonDaoTest.java
└── resources
├── db.properties
├── log4j.xml
├── test-context.xml
└── test-db.xml