Survey on Yemen, Maven, and Thymeleaf HTML Template Location

I recently discovered Yeoman , a tool that greatly facilitates the management of JS and the build life cycle of an assembly .

In addition, I use Maven as a Java tool for dependencies and builds . I am really trying to integrate both tools to get the best of both worlds.

It seems that the community has put a lot of effort into integrating Maven / Yeoman with various articles such as this one: http://addyosmani.com/blog/making-maven-grunt/ , as well as the yoman-maven plugin: https: // github. com / trecloux / yeoman-maven-plugin

Finally, I use Thymeleaf as a solution for Spring-MVC templates.

Assuming the following directory layout (see the yoman-maven-plugin module described above):

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

My question is , where should my Timeleaf templates be ?

  • In the yo/app directory? (later they will be copied to the corresponding maven directory)
  • Directly in the src/main/webapp/WEB-INF/templates ?

What I cannot understand in the case of an AngularJS application, for example, when and how templates / pages, including server-side content, can interact with the servlet container, given that Yeomen assumes that they live under its app directory ...

+4
source share
1 answer

If you are using Thymeleaf as with Spring, I assume you have something like

  <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> 

In other words, your templates should be located in the folder specified in the ServletContextTemplateResolver prefix property. In the above example, this is /WEB-INF/templates . Therefore, they must be in /src/main/webapp/WEB-INF/templates .

If you do not use ServletContextTemplateResolver , but use ClassLoaderTemplateResolver , you can place them anywhere in your path to the application class and specify it in the bean properties. There is also a FileTemplateResolver in which you can specify an absolute path anywhere in your file system.

When creating an application using Eclipse (maven plugin) folders exist

 /src /main /webapp /WEB-INF /templates /some-template.html /index.html /java /com /yourcompany /Main.java /resources /some-properties.properties 

maven will generate the following

 /WEB-INF /templates /some-template.html /index.html /classes /com /yourcompany /Main.class /some-properties.properties 

As an extended .war and specify this in your servlet container, for example. Tomcat

+2
source

Source: https://habr.com/ru/post/1502208/


All Articles