我有一个带有Spring Boot和gradle构建的Web应用程序。我从构建目录中的SCSS文件生成CSS文件,并将该文件添加到生成的WAR文件中。该文件已添加到WAR文件中,但是如果我从IntelliJ IDEA启动嵌入式Web服务器,则该文件不存在。
apply plugin: "war"
apply plugin: "org.fabric3.gradle.fabric3-sass"
...
// Generate the CSS from the SCSS files
sass {
inputFilePath = "src/main/webapp/resources/scss/my.scss"
includePaths = "src/main/webapp/resources/scss"
outputFilePath = "build/generated/src/main/webapp/resources/css/my.css"
}
war {
dependsOn compileSass
...
// Add the CSS to the WAR file
from "build/generated/src/main/webapp/"
}
// I tried to add the CSS to IDEA but if I run bootRun the CSS is not provided by the embedded server
// the WAR file is build correctly and works fine.
idea.module {
sourceDirs += file('build/generated')
resourceDirs += file('build/generated')
generatedSourceDirs += file('build/generated')
}
我希望将CSS添加到WAR文件后,由嵌入式服务器提供CSS。
这是unzip -l my.war
输出的一部分:
Archive: my.war
Length Date Time Name
--------- ---------- ----- ----
0 2019-06-24 08:24 META-INF/
149 2019-06-24 08:24 META-INF/MANIFEST.MF
0 2019-06-24 08:24 WEB-INF/
...
0 2019-06-24 07:41 resources/css/
31952 2019-06-21 14:11 resources/css/my.css
0 2019-06-24 07:41 resources/js/
0 2019-06-21 14:11 resources/js/my.js
应该放置CSS,并且在部署它时可以完美地工作,但是如果我想在IDE中调试应用程序并以gradle bootRun
启动,则嵌入式Spring服务器不提供CSS。仅WAR文件有效。