shell - WAR文件部署中的Grails Shell

标签 shell grails groovy

我正在维护一个我没有编写的Grails应用程序(实际上我没有使用Groovy / Grails的经验:)),并且目前在其所部署的一种环境中存在一个bug,而在其他环境中则没有该bug。

为了进行调试,我想跳到受影响的服务器上的grails shell 中,运行我怀疑容易出错的命令,然后查看返回的结果以查看下一步如何进行调试。

使用grails prod war命令将应用程序放入war文件中,并分发到要部署的服务器上,然后使用jar -xvf /path/to/war提取。

在grails shell 程序中时,我无法访问域中定义的任何类。

这是我尝试的方法:

`

]$ ~/grails-1.0.4/bin/grails shell

Welcome to Grails 1.0.4 - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: /home/me/grails-1.0.4        

Base Directory: /var/home/me/skills_test/WEB-INF
Running script /home/me/grails-1.0.4/scripts/Shell.groovy
Environment set to development
     [copy] Copying 1 file to /home/me/.grails/1.0.4/projects/WEB-INF
     [copy] Copying 1 file to /home/me/.grails/1.0.4/projects/WEB-INF
Jun 11, 2009 2:35:19 PM java.util.prefs.FileSystemPreferences$7 run
WARNING: Prefs file removed in background /home/me/.java/.userPrefs/org/codehaus    /groovy/tools/shell/prefs.xml
Groovy Shell (1.5.6, JVM: 10.0-b22)
Type 'help' or '\h' for help.
        ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
groovy:000> new User()
ERROR org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed,     groovysh_evaluate: 2: unable to resolve class User 
 @ line 2, column 1.
1 error

        at Shell_groovy$_run_closure2.doCall (Shell_groovy:71)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:79)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:94)
        at Shell_groovy$_run_closure2.doCall (Shell_groovy)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:79)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:79)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:94)
        at Shell_groovy$_run_closure1.doCall (Shell_groovy:37)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:79)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:94)
        at Shell_groovy$_run_closure1.doCall (Shell_groovy)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:79)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:79)
        at gant.Gant.dispatch (Gant.groovy:271)
        at gant.Gant.this$2$dispatch (Gant.groovy)
        at gant.Gant.invokeMethod (Gant.groovy)
        at gant.Gant.processTargets (Gant.groovy:436)
        at gant.Gant.processArgs (Gant.groovy:372)
groovy:000> import User
ERROR org.codehaus.groovy.tools.shell.CommandException: Invalid import definition:     'import User'; reason: startup failed, script1244745379552.groovy: 1: unable to resolve     class User
 @ line 1, column 1.
1 error

        at Shell_groovy$_run_closure2.doCall (Shell_groovy:71)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:79)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:94)
        at Shell_groovy$_run_closure2.doCall (Shell_groovy)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:79)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:79)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:94)
        at Shell_groovy$_run_closure1.doCall (Shell_groovy:37)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:79)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:94)
        at Shell_groovy$_run_closure1.doCall (Shell_groovy)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:79)
        at org.codehaus.gant.GantMetaClass.invokeMethod (GantMetaClass.java:79)
        at gant.Gant.dispatch (Gant.groovy:271)
        at gant.Gant.this$2$dispatch (Gant.groovy)
        at gant.Gant.invokeMethod (Gant.groovy)
        at gant.Gant.processTargets (Gant.groovy:436)
        at gant.Gant.processArgs (Gant.groovy:372)
groovy:000> 

`

如您所见,我无法访问“User”类(该类位于域目录中-它们与Grails的“模型”等效,对吗?),也无法导入。

我见过的grails shell使用示例都能够在不导入的情况下很好地访问应用程序中的所有类……我做错了什么?

是因为我针对提取的WAR文件运行grails shell吗?我该如何解决?

最佳答案

问题实际上是它正在从提取的WAR文件中工作-我认为它必须具有源.java文件才能正常工作。我将原始源文件复制到遇到问题的服务器上,编辑了配置以指向正确的数据源,并且能够顺利进入shell。

由于某些原因,您无法使用解压缩的WAR文件进入目录的 shell 程序,但由于我已经找到了解决方法,因此我暂时接受。

关于shell - WAR文件部署中的Grails Shell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/982886/

相关文章:

bash 脚本没有正确给出 MariaDB 服务状态

grails - 缺少方法异常

grails - Grails-尝试实例化File类对象时出现MissingPropertyException错误

java - 在 Jenkins 中为 Java 11 指定 JAVA_HOME

shell - 如何在 shell 脚本中解析配置文件 (*.conf)?

linux - 以另一个用户身份执行脚本而不是 root

shell - 在 Go 中通过管道命令从控制台读取

java - Grails-在IntellJ Idea上安装Spring Security Plugin 3.0.4的Maven错误

regex - Grails/Groovy 正则表达式 - 如何使用 (?i) 使所有内容不区分大小写?

Grails:动态调用另一个操作