11

I have a Web application in maven that follows this structure:

src
`-- main
    |-- java
    |-- resources
    `-- webapp

Is is better to put it in the main folder and then the maven plug in will try to move it or I should put it inside the webapp folder and why?

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
MexicanHacker
  • 2,685
  • 3
  • 19
  • 20

4 Answers4

25

If you don't need to filter CSS and JS files, I would simply put them in src/main/webapp (if you put them in src/main/resources, they will end up in target/classes and in WEB-INF/classes in the WAR which is very unlikely what you want). If you need to filter them, additional resources can be included in the WAR using the webResources parameter. Have a look at Adding and Filtering External Web Resources for more details.

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
6

I think they should be under src\main\webapp. The main rationale for saying this is that this is the standard suggested by Maven, and the Maven philosophy is that all projects should follow the same structure as much as possible.

lucrussell
  • 5,032
  • 2
  • 33
  • 39
2

Taken from Introduction to the Standard Directory Layout:

"If there are other contributing sources to the artifact build, they would be under other subdirectories: for example src/main/antlr would contain Antlr grammar definition files."

So I think src/main/javascript and src/main/css is the right place...

What do you think?

Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
TMarin
  • 21
  • 1
  • 1
    Very much inclined to agree with you. JavaScript and CSS are separate languages with their own nuances and use cases, not simply add ons or managed scripts bundled along java (as much as I love java!) – VLostBoy Sep 05 '13 at 20:39
0

I am seeing quite a variation of answers to this question. One set of threads (like some people in this thread) seem to think that Maven apps should place css/images/js files into the src\main\webapp folder - similar to the traditional J2EE pattern. Others feel that the resources (or another similar peer) folder outside of webapps should be used instead:

What are the conventional locations for for JSPs, JavaScript, CSS, Images in Maven web projects?

I have yet to form an opinion, but it would seem to make sense to separate these client side types of files from the server side - if only because in high performance focused production situations, the static client side files such as these are typically separated out and placed into a cacheable front end web server for faster access anyway, so keeping them in their own separate resources folder would seem to make this job easier.

Community
  • 1
  • 1
Dave McLure
  • 839
  • 1
  • 8
  • 10