之前,我在 _Events.groovy 中有这个:
eventClasspathStart = {
addResourceBundlesToClasspath()
}
但是,当我部署为 war 时,这不会被触发。如何将需要包含在 war 中的目录添加到类路径中?
最佳答案
你可以在BuildConfig.groovy中配置哪些文件包含在war中 /WEB-INF 中的任何内容都应该在类路径中获取
// This closure is passed the command line arguments used to start the
// war process.
grails.war.copyToWebApp = { args ->
fileset(dir:"web-app") {
include(name: "js/**")
include(name: "css/**")
include(name: "WEB-INF/**")
}
// This closure is passed the location of the staging directory that
// is zipped up to make the WAR file, and the command line arguments.
// Here we override the standard web.xml with our own.
grails.war.resources = { stagingDir, args ->
copy(file: "grails-app/conf/custom-web.xml", tofile: "${stagingDir}/WEB-INF/web.xml")
}
来自http://grails.org/doc/latest/guide/17.%20Deployment.html
您还可以使用 grails.war.dependencies 在 BuildConfig 中指定依赖项 在 war 中包含额外的库
def deps = [
"hibernate3.jar",
"groovy-all-*.jar",
"standard-${servletVersion}.jar",
"jstl-${servletVersion}.jar",
"oscache-*.jar",
"commons-logging-*.jar",
"sitemesh-*.jar",
"spring-*.jar",
"log4j-*.jar",
"ognl-*.jar",
"commons-*.jar",
"xstream-1.2.1.jar",
"xpp3_min-1.1.3.4.O.jar" ]
grails.war.dependencies = {
fileset(dir: "libs") {
deps.each { pattern ->
include(name: pattern)
}
}
}`
关于tomcat - 作为 war 运行时将目录添加到 grails 类路径中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6753244/