2
votes

The project is a Spring MVC with Maven.

Here is the sample folder structure :

  • src/main/java
  • src/main/resources
    • css
    • fonts
    • images
    • js
    • messages_en.properties
  • src/main/webapp
    • WEB-INF
      • views
      • application-context.xml
      • web.xml

And here is the build part of effective pom

<sourceDirectory>${basedir}\src\main\java</sourceDirectory>
<scriptSourceDirectory>${basedir}\src\main\scripts</scriptSourceDirectory>
<outputDirectory>${basedir}\target\classes</outputDirectory>
<resources>
  <resource>
    <directory>${basedir}\src\main\resources</directory>
  </resource>
</resources>
<directory>${basedir}\target</directory>
<finalName>m2mproject</finalName>

And the target directory comes out like this

  • WEB-INF
    • classes
      • com....
      • images
      • fonts
      • js
      • css
      • messages_en.properties
    • lib
    • views
    • apllication-context.xml
    • web.xml

Why maven puts all resources under the classes folder? Is my folder structure wrong ?

2
This is exactly correct. Are you having a problem?Boris the Spider
should images,fonts and js folders be under the classes folder ?paroxit
The resources are classpath resources. Everything gets put into WEB-INF/classes. These are different to remote resources - which should live in webapp outside of WEB-INF. Maven is doing exactly what it should.Boris the Spider
No, they should be on src/main/webapp/ or a subfolder of this path.Luiggi Mendoza
Hmmm.. Thank you both. I'm new to Java, it just seemed wrong, so I thought i should ask. So the files under src/main/resources are for spring to use as resource files ? Like, if I decide to call a resource property with @Value annotation, that resources file should be in that directory, am I right ?paroxit

2 Answers

2
votes

Let explain, briefly, maven behaviour

The stuff put in src/main/resources is supposed to be reachable from classpath. So in case of web application it will be put in WEB-INF/classes

The stuff put in src/main/webapp will be copied, as is, to in web application root

1
votes

Maven is doing right but since you are using spring MVC youre resources are supposed to be a static resource and should be put under

main/webapp/resources

while your pages will be under

main/webapp/WEB-INF/views

and should contains .html or .jsp pages

now for main/resources are intended for configuation files such as persistence.xml or faces properties and any other that will be used for "java" classes.