Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

eclipse dynamic web project file locations

I'm creating a new dynamic web project in Eclipse and was wondering what best practices are for folder taxonomy. Here's what I believe it is <> are folders. Can someone please verify?

 <Eclipse project name>
    <src>
        -- .java files
    <WebContent> 
        -- .html pages
        <images> 
        <css> 
        <js>
        <META-INF> 
            MANIFEST.MF 
        <WEB-INF> 
            web.xml
        <app name>
          -- .jsp pages 
like image 736
glez Avatar asked Oct 15 '12 19:10

glez


People also ask

Where does Dynamic Web Project store JS files?

js files are placed under the js sub-folder and any image files such as . jpeg or . png are placed in the images sub-folder.

Where does Dynamic Web Project store properties files?

You should have . properties file in same package as class that is using it. Or better, read properties file with getResourceAsStream method (otherwise you can have some problem later when you'll have file in . war archive).


2 Answers

Here is a sample folder structure of a dynamic web project: enter image description here

As you can see all static files are placed as sub-folders under the WebContent folder. By naming conventions .css files are places in the css sub-folder. JavaScript .js files are placed under the js sub-folder and any image files such as .jpeg or .png are placed in the images sub-folder. I also have an extra lib sub-folder where I placed an angularjs library to be used.

By default after creation of a dynamic web project your web.xml file looks like so:

 `<welcome-file-list>
 <welcome-file>index.html</welcome-file>
 <welcome-file>index.jsp</welcome-file>`

meaning it will first call the listed default name files when you run your application. This is why most projects will name the files as index.html or index.jsp. NOTE: that my index.html file is directly below the WebContent folder and not in a sub-folder

Finally you can call/include your static files (.css .js and image files) from your 'index' file like so:

    <link rel="stylesheet" href=css/bootstrap.min.css>
    <link rel="stylesheet" href=css/bootstrap-theme.min.css>

    <script type="text/javascript" src="lib/angular.min.js"></script>
    <script src="js/contactsApp.js"></script>

Also your .java files will properly go in the Java Resources -> src -> {place java files here}

like image 130
Jet_C Avatar answered Oct 20 '22 03:10

Jet_C


I am not sure why having an app-name directory under WebContent would be considered a "best practice".

Other than that, one primary rule you should be following when coming up with a directory structure is to have all static resources under one directory. In your example, I would have a subdirectory called static under WebContent, and place the js, css and images directories under it.

That way, it'd be easier for you to (later on) configure your HTTP server to pick static resources directly from the file system rather than route requests for static resources through the servlet container.

like image 30
Isaac Avatar answered Oct 20 '22 03:10

Isaac