0

I'm using the Spring Boot gradle plugin to build an executable war. I have a FindResource.java class in src/main/resources to locate files:

FindResource.class.getResource(templateName).toURI()

When I execute gradle build I get an error, that the class FindResource cannot be resolved. Do I need to the the Spring Boot gradle plugin, that it should also use classes from the resources directory. How can I do so?

My build.gradle looks as follows:

buildscript {
    ext {
        springBootVersion = '1.2.5.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 
        classpath("io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot' 
apply plugin: 'io.spring.dependency-management' 

jar {
    baseName = 'abc'
    version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenCentral()
}


dependencies {
    compile("org.springframework.boot:spring-boot-starter-data-jpa")
    compile("org.springframework.boot:spring-boot-starter-jersey")
    compile("org.springframework.boot:spring-boot-starter-web")
    compile("org.apache.pdfbox:pdfbox:1.8.10")
    compile('org.apache.poi:poi-ooxml:3.12')
    compile('org.apache.poi:poi-scratchpad:3.12')
    runtime("org.hsqldb:hsqldb")
    testCompile("org.springframework.boot:spring-boot-starter-test") 
}


task wrapper(type: Wrapper) {
    gradleVersion = '2.3'
}
Daniel
  • 834
  • 1
  • 9
  • 25
  • 5
    Why don't you put the class in src/main/java, where it belongs? src/main/resources is for resource files (as the name says). – dunni Aug 12 '15 at 09:35

1 Answers1

0

As mentioned in the comment class files to load need to be in src/main/java/ and not in src/main/resources. This link may help give you more information on the convention of this structure.

Community
  • 1
  • 1
Rob Baily
  • 2,770
  • 17
  • 26