eclipse - 关于 Yeoman、Maven 和 Thymeleaf HTML 模板位置的询问

标签 eclipse maven war yeoman thymeleaf

我最近发现 Yeoman ,极大方便的工具 JS 依赖和构建生命周期管理 .

此外,我使用 Maven 作为我的 Java 依赖和构建工具。我实际上是在寻求整合这两种工具,以便我能够两全其美。

看来社区在 上付​​出了很多努力Maven/Yeoman 整合各种文章,例如这篇:http://addyosmani.com/blog/making-maven-grunt/以及 yeoman-maven 插件 :https://github.com/trecloux/yeoman-maven-plugin

最后,我使用 Thymeleaf作为我的 Spring-MVC 模板解决方案。

假设以下目录布局(参见上面的 yeoman-maven-plugin):

pom.xml
 - src
   - main
     - java
     - webapp
     - …
   - test
     - ..
 - yo
   package.json
   component.json
   Gruntfile.js
   - app
     index.html
     ...
   - test
     ...
   - dist
     ...

我的问题是 我的 Thymeleaf 模板应该放在哪里 ?
  • yo/app目录? (它们随后会被 maven 复制到适当的目录中)
  • 直属src/main/webapp/WEB-INF/templates目录?

  • 的情况下我无法弄清楚什么AngularJS 例如,考虑到 Yeoman 假定模板/页面位于其 app 下,应用程序是何时以及如何与 servlet 容器交互的模板/页面,包括服务器端内容。目录...

    最佳答案

    如果您正在使用 Thymeleaf作为您的 templating engine with Spring ,我假设你有类似的东西

      <bean id="templateResolver"
            class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
        <property name="prefix" value="/WEB-INF/templates/" />
        <property name="suffix" value=".html" />
        <property name="templateMode" value="HTML5" />
      </bean>
    
      <bean id="templateEngine"
            class="org.thymeleaf.spring3.SpringTemplateEngine">
        <property name="templateResolver" ref="templateResolver" />
      </bean>
    
      <bean class="org.thymeleaf.spring3.view.ThymeleafViewResolver">
        <property name="templateEngine" ref="templateEngine" />
      </bean>   
    

    换句话说,您的模板应该位于 ServletContextTemplateResolver 中指定的文件夹中。属性(property)prefix .在上面的例子中,就是 /WEB-INF/templates .因此,这些应该在 /src/main/webapp/WEB-INF/templates 中.

    如果您没有使用 ServletContextTemplateResolver ,而是使用 ClassLoaderTemplateResolver ,您可以将它们放在应用程序类路径中的任何位置,并在该 bean 的属性中指定它。还有一个FileTemplateResolver您可以在其中指定文件系统上任何位置的绝对路径。

    使用 Eclipse(maven 插件)构建应用程序时,具有文件夹
    /src
        /main
            /webapp
                /WEB-INF
                    /templates
                        /some-template.html
                /index.html
            /java
                /com
                    /yourcompany
                        /Main.java
            /resources
                /some-properties.properties
    

    maven 将生成以下内容
    /WEB-INF
        /templates
             /some-template.html
        /index.html
    /classes 
        /com
            /yourcompany
                 /Main.class
        /some-properties.properties
    

    作为扩展 .war并将其提供给您的 servlet 容器,例如。 Tomcat 。

    关于eclipse - 关于 Yeoman、Maven 和 Thymeleaf HTML 模板位置的询问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18806078/

    相关文章:

    eclipse - 从 Github 导入 Ant 项目

    eclipse - 无法完成安装 Google Plugin for eclipse

    java - 无法初始化类 com.amazonaws.services.sqs.AmazonSQSClient

    java - Eclipse 自动部署不包括 native 库

    java - 如何将多个WAR文件打包到一个Maven项目中?

    java.lang.IllegalArgumentException : URI is not hierarchical (in deployed application) 异常

    java - 如何在eclipse中以分层 View 创建包

    c - 此行有多个标记 - 语法错误 (eclipse)

    java.lang.NoClassDefFoundError : org/springframework/web/client/ResponseErrorHandler 错误

    java - 为什么 Maven Ear 包使用项目的旧 jar 版本,尽管 war 子项目包含最新的 jar 版本?