如何在已部署的grails应用程序中找到GSP文件的物理路径 [英] How to find the physical path of a GSP file in a deployed grails application

查看:83
本文介绍了如何在已部署的grails应用程序中找到GSP文件的物理路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要找出grails GSP文件的物理路径。

我的要求是我想在运行时创建一个新的布局文件并在应用程序中使用它。

在应用程序运行于jetty(grails run-app)时,我已经能够实现这个功能,但是,当我在Jboss上部署应用程序时,该文件需要创建的变化。所以,理想情况下,我想在运行时使用一些神奇的工具找出特定GSP的路径(可以说main.gsp布局文件),并且我需要创建它我的新布局位于main.gsp所在的同一目录中。



任何指针?

-Deepak

解决方案

以下是一些常规代码,用于查找生产环境中的布局文件夹路径(例如,当部署为jboss上的war时):

  import org.codehaus.groovy.grails.commons.ApplicationHolder 

...

文件layoutFolder = ApplicationHolder.application.parentContext .getResource(WEB-INF / grails-app / views / layouts)。文件
def absolutePath = layoutFolder.absolutePath
println布局文件夹的绝对路径:$ {absolutePath}
File newLayoutFile = new File(layoutFolder,foo.gsp)

要使用新创建的布局,您可能需要重新启动Web应用程序或容器,因为视图在生产模式下被分割。


I need to find out the physical path of a grails GSP file.

My requirement is that I want to create a new layout file at run-time and use that in the application.

I have been able to achieve this without problem when the application runs on jetty (grails run-app), however, when I deploy the app on Jboss, the path at which the file needs to be created changes.

So, ideally I would like to find out at runtime using some magical utility the path of a particular GSP (lets say main.gsp layout file) and I need to create my new layout in the same directory in which main.gsp reside.

Any pointers?

-Deepak

解决方案

Here is some groovy code to lookup the layout-folder path in the production environment (eg. when deployed as war on jboss):

import org.codehaus.groovy.grails.commons.ApplicationHolder

...

File layoutFolder = ApplicationHolder.application.parentContext.getResource("WEB-INF/grails-app/views/layouts").file      
def absolutePath = layoutFolder.absolutePath
println "Absolute Path to Layout Folder: ${absolutePath}"
File newLayoutFile = new File(layoutFolder, "foo.gsp")

To use the newly created layout, you probably will need to restart the web-application or the container, since the views are chached in production mode.

这篇关于如何在已部署的grails应用程序中找到GSP文件的物理路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆