Maven and JSF webapp structure, where exactly to put JSF resources

╄→гoц情女王★ 提交于 2019-11-26 06:40:11

问题


I don\'t really understand the structure of directories with Maven and JSF webapp.

When I generate project I have this structure :

src
|_ main
   |_ java
   |_ resources
   |_ webapp
      |_ WEB-INF 
         |_ web.xml
      |_ index.xhtml

I want to include some resources :

  • javascript file
  • css file
  • images
  • i18n files

I can include i18n files inside src/main/resources but not anywhere and I can include JS file, CSS file and images inside src/main/webapp/resources but not anywhere...

I didn\'t find very clear rules on the web about directories structure with JSF and Maven.

What are the rules please ?

Thanks


回答1:


JSF resources which are to be referenced by <h:outputStylesheet>, <h:outputScript> and <h:graphicImage> (thus, CSS/JS/images), should end up in /resources folder of the public webcontent, there where the /WEB-INF and /META-INF folders also are.

Thus, you've to put them in /src/main/webapp/resources.

src
 `-- main
      |-- java
      |-- resources
      `-- webapp
           |-- resources
           |    |-- css
           |    |    `-- style.css
           |    |-- images
           |    |    `-- logo.png
           |    `-- js
           |         `-- script.js
           |-- WEB-INF 
           |    `-- web.xml
           `-- index.xhtml

Those i18n files (I assume you technically meant resource bundle files) have ultimately to end up in a package in /WEB-INF/classes. The /src/main/resources is intented for non-class files which are supposed to end up in /WEB-INF/classes, you should put them in there. Assuming a bundle base name of com.example.i18n.text, provide them as such:

src
 `-- main
      |-- java
      |-- resources
      |    `-- com
      |         `-- example
      |              `-- i18n
      |                   |-- text.properties
      |                   |-- text_en.properties
      |                   |-- text_es.properties
      |                   `-- text_nl.properties
      :                   

See also:

  • How to reference CSS / JS / image resource in Facelets template?
  • What is the JSF resource library for and how should it be used?



回答2:


The best location for css/images etc is in src/main/webapp/images or src/main/webapp/css/ etc. Currently there is no location src/main/webapp/resources. The src/main/resources folder is intended for resources (property files etc.) which should be filtered or should be located into WEB-INF/classes folder. So usualy you don't like to filter images and css files. Take a look into the maven-war-plugin documentation which gives some hints and configuration examples. The best approach seemed to be to put everything into src/main/webapp/FOLDER which shouldn't be filtered in anyway otherwise you should put it into src/main/resources and you can control the filtering and the replacements



来源:https://stackoverflow.com/questions/13540907/maven-and-jsf-webapp-structure-where-exactly-to-put-jsf-resources

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!