Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java EE eclipse project directory structure?

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!

like image 584
jim Avatar asked Jan 19 '10 02:01

jim


People also ask

What is project structure in Eclipse?

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.

What is the root directory of a project in Eclipse?

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.

What is Java folder structure?

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.


1 Answers

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

like image 187
Pascal Thivent Avatar answered Sep 23 '22 15:09

Pascal Thivent