我正在使用Spring Boot gradle插件来构建可执行文件。我在src / main / resources中有一个FindResource.java类来查找文件:
FindResource.class.getResource(templateName).toURI()
当我执行gradle build时,我得到一个错误,该类FindResource无法解析。我需要Spring Boot gradle插件吗,它还应该使用resources目录中的类。我该怎么办?
我的build.gradle如下所示:
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'
}
最佳答案
如注释类中所述,要加载的文件必须位于src / main / java /中,而不是src / main / resources中。 This link可以帮助您提供有关此结构约定的更多信息。
关于java - 找不到主要/资源中的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31959764/