【发布时间】:2018-04-02 13:54:19
【问题描述】:
我有一个基本的 Java 应用程序,我想在其中使用 WebJars。我使用 Gradle 作为我的构建系统。我想将 WebJars 用于 Bootstrap 和 JQuery,这样我就可以在我的 Spring-Boot/ThymeLeaf 应用程序中轻松引用和更新它们。该应用程序基本上是位于here的表单教程中的应用程序
据我了解,Gradle 应该将 WebJars 中的所有文件放入我的 Jar 文件中的 META-INF 文件夹中。如果我正确理解所有内容,那么当我在我的 html 页面中引用以/webjars/ 开头的内容时,Spring-Boot 资源处理程序将从META-INF/ 加载资源
不幸的是,这不起作用(还)。因为我在 Tomcat 的日志输出中看到资源处理程序已正确安装。我决定检查这些文件是否真的在我的 Jar 文件中。
当我提取我的 Jar 文件时,META-INF 文件夹只有一个名为 MANIFEST.MF 的文件,其中包含有关 Spring Boot 的一些信息。 BOOT-INF/lib 中有一个 BootStrap-3.3.7.Jar 和一个 JQuery-3.2-1.Jar 文件,但我认为这不是它们应该结束的地方。 (或者我错了,资源处理程序中的某个地方有错误吗?)。
当我运行 gradle build 时,如何告诉 gradle 对这些文件做正确的事情?
我的 gradle.build 文件如下所示:
buildscript {
ext {
springBootVersion = '1.5.8.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: "jacoco"
jar {
baseName = 'gs-serving-web-content'
version = '0.0.1'
}
bootRun {
addResources = true
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.webjars:jquery:3.2.1")
compile("org.webjars:bootstrap:3.3.7")
testCompile("org.springframework.boot:spring-boot-starter-test")
}
【问题讨论】:
标签: java spring-boot gradle webjars