Results 1 to 1 of 1
  1. #1
    rain13 is offline Member
    Join Date
    Mar 2017
    Posts
    5
    Rep Power
    0

    Default I need help with reading templates from jar.

    Hi.

    I have a problem with using my thymeleaf templates in jar. I have my index file in src/main/webapp/thymeleaf/index.html and in jar file it is located in /BOOT-INF/classes/thymeleaf/index.html. When I run it from idea, everything works fine, but when I run the jar file it says:
    Java Code:
    org.thymeleaf.exceptions.TemplateInputException: Error resolving template "index", template might not exist or might not be accessible by any of the configured Template Resolvers
    Does anyone know how I can fix it? In case anyone wonders about webapp directory... I used it because this directory structure allows me hot reloading of js/html/css when I am developing it in ide. I heard recommendation that I should put my templates to src/main/resources but even then when I had them in src/main/resources/webapp/thymeleaf I still received the same error. I am not very advanced in spring therefore I would appreciate beginner friendly guidance. Thanks in advance.


    I have this configuration class:
    Java Code:
    @Configuration
    public class WebConfiguration extends WebMvcConfigurerAdapter {
    
    
        @Override
        public void addViewControllers(ViewControllerRegistry registry) {
            registry.addViewController("/").setViewName("index");
            registry.addViewController("/upload").setViewName("upload");
        }
    
        @Bean
        public ITemplateResolver templateResolver() {
            SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
            resolver.setPrefix("/BOOT-INF/classes/thymeleaf/");
            return resolver;
        }
    }
    And this pom.xml

    Java Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <modelVersion>4.0.0</modelVersion>
    
      <groupId>org.springframework</groupId>
      <artifactId>gs-spring-boot</artifactId>
      <version>0.1.0</version>
    
      <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.3.RELEASE</version>
      </parent>
    
      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <start-class>thesis.ApplicationRunner</start-class>
      </properties>
    
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>4.11</version>
          <scope>test</scope>
        </dependency>
        <dependency>
          <groupId>org.apache.httpcomponents</groupId>
          <artifactId>httpclient</artifactId>
          <version>4.5.1</version>
          <scope>compile</scope>
          <exclusions>
            <exclusion>
              <artifactId>commons-logging</artifactId>
              <groupId>commons-logging</groupId>
            </exclusion>
          </exclusions>
        </dependency>
        <dependency>
          <groupId>org.webjars</groupId>
          <artifactId>bootstrap</artifactId>
          <version>3.3.6</version>
          <scope>compile</scope>
          <exclusions>
            <exclusion>
              <artifactId>commons-logging</artifactId>
              <groupId>commons-logging</groupId>
            </exclusion>
          </exclusions>
        </dependency>
        <dependency>
          <groupId>commons-io</groupId>
          <artifactId>commons-io</artifactId>
          <version>2.4</version>
          <scope>compile</scope>
          <exclusions>
            <exclusion>
              <artifactId>commons-logging</artifactId>
              <groupId>commons-logging</groupId>
            </exclusion>
          </exclusions>
        </dependency>
        <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-web</artifactId>
          <scope>compile</scope>
          <exclusions>
            <exclusion>
              <artifactId>commons-logging</artifactId>
              <groupId>commons-logging</groupId>
            </exclusion>
          </exclusions>
        </dependency>
        <dependency>
          <groupId>org.webjars</groupId>
          <artifactId>jquery</artifactId>
          <version>2.2.0</version>
          <scope>compile</scope>
          <exclusions>
            <exclusion>
              <artifactId>commons-logging</artifactId>
              <groupId>commons-logging</groupId>
            </exclusion>
          </exclusions>
        </dependency>
        <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-thymeleaf</artifactId>
          <scope>compile</scope>
          <exclusions>
            <exclusion>
              <artifactId>commons-logging</artifactId>
              <groupId>commons-logging</groupId>
            </exclusion>
          </exclusions>
        </dependency>
        <dependency>
          <groupId>commons-lang</groupId>
          <artifactId>commons-lang</artifactId>
          <version>2.3</version>
          <scope>compile</scope>
          <exclusions>
            <exclusion>
              <artifactId>commons-logging</artifactId>
              <groupId>commons-logging</groupId>
            </exclusion>
          </exclusions>
        </dependency>
        <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-autoconfigure</artifactId>
          <version>1.4.3.RELEASE</version>
        </dependency>
        <dependency>
          <groupId>com.fasterxml.jackson.dataformat</groupId>
          <artifactId>jackson-dataformat-csv</artifactId>
          <version>2.7.0</version>
        </dependency>
        <dependency>
          <groupId>org.projectlombok</groupId>
          <artifactId>lombok</artifactId>
          <version>1.16.6</version>
        </dependency>
        <dependency>
          <groupId>info.cukes</groupId>
          <artifactId>gherkin</artifactId>
          <version>2.12.2</version>
        </dependency>
        <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-configuration-processor</artifactId>
          <optional>true</optional>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>springloaded</artifactId>
          <version>1.2.6.RELEASE</version>
          <type>pom</type>
        </dependency>
        <dependency>
          <groupId>net.sourceforge.nekohtml</groupId>
          <artifactId>nekohtml</artifactId>
          <version>1.9.21</version>
        </dependency>
      </dependencies>
    
      <build>
        <resources>
          <resource>
            <directory>src/main/webapp</directory>
          </resource>
          <resource>
            <directory>src/main/resources</directory>
          </resource>
        </resources>
        <plugins>
          <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
          </plugin>
        </plugins>
      </build>
    
    </project>
    Attached Thumbnails Attached Thumbnails I need help with reading templates from jar.-tree.png  

Similar Threads

  1. Email templates
    By charanyevadu in forum New To Java
    Replies: 1
    Last Post: 03-27-2012, 08:56 AM
  2. Java Templates
    By llee in forum New To Java
    Replies: 4
    Last Post: 02-10-2012, 11:10 PM
  3. HELP! - Eclipse Templates
    By protocos in forum Eclipse
    Replies: 1
    Last Post: 03-06-2009, 02:31 AM
  4. Templates JSP
    By Eric in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 07-04-2007, 07:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •