I am attempting to setup a sample dynamic web project in Eclipse using Java EE, Spring and Maven (using Nexus repository manager). I was wondering if anybody knows the "best practice" directory structure that I should setup for an enterprise web app in Eclipse? Should I just stick with the default structure that is setup for me? I ask because looking around the internet I see wide variation (for instance, where the WEB-INF and META-INF folders are..if there is a 'war' directory etc.). Thanks!
Workspace and Project OrganizationWhenever you make a project inside of Eclipse, Eclipse will auto-magically create a new folder in your workspace with the same name. Inside of that folder it will create two folders: bin, and src (source). The bin folder can be ignored.
Eclipse designates a root folder in which to house sub-folders for projects and their resources. You can set up multiple workspaces if you want, but at any one time you will only have one open in Eclipse at a time. Chances are that you will need only one workspace for all of your work in this course.
Folder Structure of Java Projects. When you create a Java project, Application Platform creates a folder structure that contains the following folder types: Source Folders. The source folders contain the Java source files and unit test source code.
If you use Maven, I'd warmly recommend to just follow Maven's convention. This is the "best practice" in Maven's world (and I don't see any good reasons to not do so, not following this advice will lead to more work).
One easy way to create a webapp project is to use the maven-archetype-webapp:
mvn archetype:generate -DarchetypeArtifactId=maven-archetype-webapp \
-DgroupId=com.mycompany.app \
-DartifactId=my-webapp \
-Dversion=1.0-SNAPSHOT
(You can paste this command "as is" in a Linux shell; on Windows, type everything on single line without the "\"
.)
And this is the structure you'll get:
my-webapp
|-- pom.xml
`-- src
`-- main
|-- resources
`-- webapp
|-- WEB-INF
| `-- web.xml
`-- index.jsp
This layout is compliant with Eclipse WTP (whatever plugin you're using for the Eclipse integration). Just import this project into Eclipse and there you go.
If you have more specific question, feel free to ask (for example, most of time you don't have to worry about the META-INF
directory, but put it under src/main/resources
if really you need to have it).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With