【问题标题】:How do I get the Current Working Directory for Grails/Tomcat Webapp?如何获取 Grails/Tomcat Webapp 的当前工作目录?
【发布时间】:2011-12-18 09:51:00
【问题描述】:

我为 Tomcat 编写了一个 Grails Web 应用程序,它打开并从 ./data/transactions/foobar 上的伯克利数据库读取数据。

这段代码在我的 Eclipse 环境中运行良好。

但是当我将它移动到服务器时,它会吐出这个异常。当我将 WAR 文件中的 Grails 作为服务器上的 webapps Web 应用程序部署时,我不确定当前工作目录在哪里。

com.sleepycat.je.EnvironmentNotFoundException: (JE 4.1.10) ./data/transactions/Foobar
Home directory: ./data/transactions/Foobar ENV_NOT_FOUND: 
EnvironmentConfig.setAllowCreate is false so environment creation is not permitted, but there are no log files in the environment directory. Environment is invalid and must be closed.

我在 Linux 服务器上的 Tomcat 安装目录是 /usr/share/tomcat6。 webapps 根目录是 /usr/share/tomcat6/webapps。我们的WAR目录是安装在一个名为“bridge”的子目录中。我的 Grails 应用程序的 WAR 路径位于 /usr/share/tomcat6/webapps/bridge

我尝试将 ./data/transaction/Foobar 同时放在 /usr/share/tomcat6/webapps 和 /usr/share/tomcat6/webapps/bridge 中,但没有成功。

我也尝试将 ./data/transaction/Foobar 放入 /usr/share/tomcat6 安装基目录,但也没有成功。

以下是我从 Tomcat 服务器看到的错误:

Error 500: Executing action [index] of controller[com.ecmhp.ecmdatabridge.generators.GenerateEmiDigestsController] 
caused exception: (JE 4.1.10) ./data/transactions/Foobar 
    Home directory: ./data/transactions/Foobar ENV_NOT_FOUND: 
    EnvironmentConfig.setAllowCreate is false so environment creation is not permitted, but there are no log files in the environment directory. Environment is invalid and must be closed.

Servlet:grails

URI:/bridge/grails/generateEmiDigests/index.dispatch

Exception Message: (JE 4.1.10) ./data/transactions/Foobar 
Home directory: ./data/transactions/Foobar ENV_NOT_FOUND: 
EnvironmentConfig.setAllowCreate is false so environment creation is not permitted, but there are no log files in the environment directory. Environment is invalid and must be closed. 

Caused by: (JE 4.1.10) ./data/transactions/Foobar 
    Home directory: ./data/transactions/Foobar ENV_NOT_FOUND: 
    EnvironmentConfig.setAllowCreate is false so environment creation is not permitted, but there are no log files in the environment directory. Environment is invalid and must be closed.

知道如何为我的 Tomcat WAR 设置当前工作目录,以便它找到 Berkeley DB ./data/transaction 文件吗?或者任何想法我可以找出我的 Grails 应用程序启动的当前工作目录是什么?

【问题讨论】:

    标签: tomcat grails working-directory


    【解决方案1】:

    如果您可以获取“grailsApplication”bean,它可以或可以自动注入到 Grails 框架的不同部分,您可以尝试:

    grailsApplication.mainContext.servletContext.getRealPath('/data/transactions/foobar')
    

    【讨论】:

      【解决方案2】:

      如果你为 grails 安装了控制台插件,你可以直接运行

      new File( 'test.html' ).absolutePath
      

      对于我们的应用程序,这会返回 /data/opt/tomcat/5.5/,所以我想您需要将目录放在 usr/share/tomcat6/data/transactions 中

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-04-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-09-18
        • 2020-02-24
        • 2013-06-26
        • 1970-01-01
        相关资源
        最近更新 更多