tomcat - 作为 war 运行时将目录添加到 grails 类路径中?

标签 tomcat grails groovy classpath war

之前,我在 _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/

相关文章:

java - 在 linux 上安装 JDK7

java - 有没有办法在 tomcat 8 中维护当前登录的用户信息?

grails - Grails操作适用于GET请求,针对POST请求返回404

Groovy 和 Groovy++,它们有区别吗?

grails - 以编程方式呈现 GSP

tomcat - 尝试在 Ozone Widget Framework 的 owfConfig.groovy 中加密数据源密码

tomcat - 部署为 WAR 时如何保留 Railo/app 设置?

twitter-bootstrap - 我需要做什么才能在 GRAILS 项目的 Bootstrap 上使用 smartmenus?

grails - 动态默认属性 grails

Grails按键排序 map