【发布时间】:2015-08-12 08:21:46
【问题描述】:
我正在使用 Spring Boot gradle 插件来构建一个可执行的战争。我在 src/main/resources 中有一个 FindResource.java 类来定位文件:
FindResource.class.getResource(templateName).toURI()
当我执行 gradle build 时,我收到一个错误,即类 FindResource 无法解析。我是否需要 Spring Boot gradle 插件,它还应该使用资源目录中的类。我该怎么做?
我的 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 用于资源文件(顾名思义)。
标签: java gradle spring-boot