简体   繁体   English

src / main / resources下的文件位于target / WEB-INF / classes下

[英]Files under src/main/resources goes under target/WEB-INF/classes

The project is a Spring MVC with Maven. 该项目是带有Maven的Spring MVC。

Here is the sample folder structure : 这是示例文件夹结构:

  • src/main/java 的src /主/ JAVA
  • src/main/resources 的src / main /资源
    • css CSS
    • fonts 字体
    • images 图片
    • js JS
    • messages_en.properties messages_en.properties
  • src/main/webapp 的src /主/ web应用
    • WEB-INF WEB-INF
      • views 意见
      • application-context.xml 应用程序的context.xml
      • web.xml web.xml中

And here is the build part of effective pom 这是有效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 WEB-INF
    • classes
      • com.... COM ....
      • images 图片
      • fonts 字体
      • js JS
      • css CSS
      • messages_en.properties messages_en.properties
    • lib LIB
    • views 意见
    • apllication-context.xml apllication-的context.xml
    • web.xml web.xml中

Why maven puts all resources under the classes folder? 为什么Maven将所有资源都放在classes文件夹下? Is my folder structure wrong ? 我的文件夹结构不正确吗?

Let explain, briefly, maven behaviour 让我们简要地解释一下行家的行为

The stuff put in src/main/resources is supposed to be reachable from classpath. 放在src / main / resources中的东西应该可以从classpath到达。 So in case of web application it will be put in WEB-INF/classes 因此,在Web应用程序的情况下,它将被放在WEB-INF / classs中

The stuff put in src/main/webapp will be copied, as is, to in web application root 放入src / main / webapp的内容将原样复制到Web应用程序的根目录中

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 Maven做得很好,但是由于您使用的是Spring MVC,因此您的资源应该是静态资源,应该放在

main/webapp/resources 主/ web应用/资源

while your pages will be under 而您的页面将处于

main/webapp/WEB-INF/views 主/ web应用/ WEB-INF /视图

and should contains .html or .jsp pages 并且应包含.html或.jsp页面

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. 现在,用于主要/资源的资源用于配置文件,例如persistence.xml或faces属性以及将用于“ java”类的任何其他文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 webapp / WEB-INF或src / main / resources下的资源文件? - resource files under webapp/WEB-INF or src/main/resources? src / main / resources下的哪些文件以及WEB-INF下的文件? - which files under src/main/resources and files under WEB-INF? Maven将applicationContext.xml从src / main / resources复制到target / myproject / WEB-INF - Maven copying applicationContext.xml from src/main/resources to target/myproject/WEB-INF applicationContext.xml从src / main / resources复制到/ WEB-INF / classes - applicationContext.xml is being copied to /WEB-INF/classes from src/main/resources Gradle WAR 与 WEB-INF/classes 下的编译类 - Gradle WAR with compiled classes under WEB-INF/classes 如何将.class下的web-inf / classs打包为jar并将其放入web-inf / lib目录 - how to package the .class under the web-inf/classes as a jar and put it to the web-inf/lib dir 在WAR文件的WEB-INF文件夹下打包Java类 - Package Java classes under WEB-INF folder in WAR file 将文件放在WEB-INF目录下并读取它们 - Placing files under WEB-INF directory and reading them Struts 2 Convention插件和WEB-INF下的JSP文件 - Struts 2 Convention Plugin and JSP files under WEB-INF 为什么WEB-INF文件夹里面的jsp文件有效,但放在WEB-INF下的文件夹下不行? - Why jsp files inside WEB-INF folder works , but placed under a folder under WEB-INF doesn't?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM