title: Resolve css link Thymeleaf external project
body: <p>I am making a small framework for sending emails to be used in the community. In this framework there is the possibility of sending pre-defined emails. To resolve the HTML files (in my external .jar project) using Thymeleaf I am using the following code:</p>
  
  <pre><code>//Here I build a specific Template Resolver (FileTemplateResolver) and add it to the 
  //SpringTemplateEngine already created (by Spring Boot) with the lowest priority,
  //to resolve the HTML files that are in my external project in
  //resources / templates / mailTemplates / templatesPreDefined.
  @PostConstruct
  public void customTemplateResolver(){
  
      try {
  
          templateEngine.addTemplateResolver(getTemplateResolver());
  
      } catch (Exception e) {
  
          LOGGER.debug("Não foi possível definir um template resolver customizado para que seja utilizado"
                  + " os templates pré definidos.", e);
  
      }
  
  }
  
  private ITemplateResolver getTemplateResolver() throws CustomTemplateResolverException {
  
      FileTemplateResolver resolver = new  FileTemplateResolver();
  
      resolver.setPrefix(getPrefixTemplateResolver());        
      resolver.setSuffix(".html");
      resolver.setTemplateMode("HTML5");
      resolver.setCharacterEncoding("UTF-8");
      resolver.setCacheable(false);
      resolver.setOrder(Ordered.LOWEST_PRECEDENCE);
  
      return resolver;
  }
  
  private String getPrefixTemplateResolver() throws CustomTemplateResolverException{
  
      try {           
  
          return getClass().getProtectionDomain().getCodeSource().getLocation().toURI().getPath() 
                  + "templates" + BARRA + "mailTemplates" + BARRA + "templatesPredefined" + BARRA;
  
      } catch (URISyntaxException e) {
  
          LOGGER.debug("Não foi possível obter o prefixo (classpath) do template resolver.", e);
  
          throw new CustomTemplateResolverException("Não foi possível obter o prefixo (classpath) do template resolver.", e);
  
      }
  
  }
  
  //In the section below is where to process the HTML files of my external project.
  @Autowired
  private TemplateEngine templateEngine;
  
  @Autowired
  private Context context;
  
  templateEngine.process("mailTemplate", context)
  </code></pre>
  
  <p>This works very well, but in order to make the code more organized, I would not like to put all css inside the HTML, but in an external file that I will import later. But when I use the code below <code>th:href="@{/css/app/app.css}"</code></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en" xmlns="http://www.w3.org/1999/xhtml"    xmlns:th="http://www.thymeleaf.org"&gt;
  &lt;head&gt;
  //I need to import this app.css which is in my 
  //resources/static/css/app/app.css folder in my external project.
  &lt;link id="appcss" rel="stylesheet" th:href="@{/css/app/app.css}" /&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;span style="color: red; border-color: 1px solid red;" th:text="${message}"&gt;    &lt;/span&gt;
  &lt;span class="teste"&gt;Mail Template&lt;/span&gt;
  &lt;/body&gt;
  &lt;/html&gt; 
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>Link base "/css/app/app.css" cannot be context relative (/) or page relative 
  unless you implement the org.thymeleaf.context.IWebContext interface 
  (context is of class: org.thymeleaf.context.Context) (mailTemplate:4)
  </code></pre>
  
  <p>This my project will run as an external library to the main project, so the context and path I have is the main project. How do I set a resources folder and have thymeleaf identify the same in importing features in a project that will execute as a library (.jar)?</p>
  
  <p>Note: The two projects (primary and secondary) are using Spring Boot 1.4 and consequently the aggregate version of Thymeleaf.</p>