我为Tomcat写了一个Grails webapp,它打开并从./data/transactions/foobar上的Berkeley DB中读取。
此代码在我的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 root目录是/ 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应用程序?
答案 0 :(得分:8)
如果你能掌握'grailsApplication'bean,它可以在Grails框架的不同部分自动注入,你可以尝试:
grailsApplication.mainContext.servletContext.getRealPath('/data/transactions/foobar')
答案 1 :(得分:1)
如果您安装Grails的Console插件,则可以运行
new File( 'test.html' ).absolutePath
对于我们的应用程序,这会返回/data/opt/tomcat/5.5/,所以我想你需要将你的目录放在usr / share / tomcat6 / data / transactions中