Grails 初学者问题“无法调用 Servlet 2.5”

发布于 2024-09-02 09:33:18 字数 3032 浏览 2 评论 0原文

[更新]

显然我不是唯一遇到这个问题的人 - http://grails.1312388.n4.nabble.com/Beginner-ERROR-Failed-to-invoke-Servlet-2-5-getContextPath-method-td2222279 .html 。它也出现在 Windows 计算机和 OS X 上的 Netbeans IDE 中。

此时,让我特别困惑的部分是,我可以在 Eclipse 中很好地运行我的 Grails 应用程序,但是当我尝试运行它们时他们从航站楼轰炸。据我所知,它们都是从 grails-core 目录运行的,那么为什么它可以在 Eclipse 中运行而不是从终端运行呢?

[/更新]

我正在尝试在 Snow Leopard 机器上设置 Grails。我遵循了 grails.com 的所有安装说明,并尝试从 Dave Klein 编写的 Grails:快速入门指南中启动该应用程序。我运行了 grails create-app TekDays ,没有出现任何明显问题,并且能够 cd 到 TekDays 文件夹,但是当我尝试运行 grails run-app 时,我得到以下信息:

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

Base Directory: /apps/TekDays
Resolving dependencies...
Dependencies resolved in 4469ms.
Running script /grails/scripts/RunApp.groovy
Environment set to development
   [delete] Deleting directory /Users/name/.grails/1.3.1/projects/TekDays/tomcat
Running Grails application..
2010-05-24 21:42:39,559 [main] ERROR context.GrailsContextLoader  - Error executing bootstraps: Failed to invoke Servlet 2.5 getContextPath method
java.lang.IllegalStateException: Failed to invoke Servlet 2.5 getContextPath method
    at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:164)
    at grails.web.container.EmbeddableServer$start.call(Unknown Source)
    at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:159)
    at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy)
    at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:282)
    at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
    at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:150)
    at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy)
    at _GrailsRun_groovy.runInline(_GrailsRun_groovy:116)
    at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy)
    at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:59)
    at RunApp$_run_closure1.doCall(RunApp.groovy:33)
    at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
    at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
    at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
    at gant.Gant.withBuildListeners(Gant.groovy:427)
    at gant.Gant.this$2$withBuildListeners(Gant.groovy)
    at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
    at gant.Gant.dispatch(Gant.groovy:415)
    at gant.Gant.this$2$dispatch(Gant.groovy)
    at gant.Gant.invokeMethod(Gant.groovy)
    at gant.Gant.executeTargets(Gant.groovy:590)
    at gant.Gant.executeTargets(Gant.groovy:589)
Caused by: java.lang.NoSuchMethodException: javax.servlet.ServletContext.getContextPath()
    at java.lang.Class.getMethod(Class.java:1605)
    ... 23 more

我已经用谷歌搜索了我能想到的“无法调用 Servlet 2.5”的所有衍生内容,但迄今为止无法找到任何可以帮助我理解该错误的内容,但只能单独解决该错误。

任何帮助我解决这个问题的建议将非常感激!

[UPDATE]

Apparently I'm not the only one with this problem - http://grails.1312388.n4.nabble.com/Beginner-ERROR-Failed-to-invoke-Servlet-2-5-getContextPath-method-td2222279.html . It has also appeared on a Windows machine and in the Netbeans IDE on OS X.

At this point, the part that has me particularly perplexed, is I can run my Grails apps just fine from within Eclipse, but the second I try to run them from the Terminal they bomb. As far as I can tell, they are both being run from the grails-core directory, so why would it work from within Eclipse but not from the Terminal?

[/UPDATE]

I'm trying to get Grails set up on a Snow Leopard machine. I followed all the grails.com install directions and am trying to start the application from Grails: A Quick-Start Guide by Dave Klein. I ran grails create-app TekDays with no apparent problems and was able to cd to the TekDays folder, but when I try to run grails run-app I get the following:

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

Base Directory: /apps/TekDays
Resolving dependencies...
Dependencies resolved in 4469ms.
Running script /grails/scripts/RunApp.groovy
Environment set to development
   [delete] Deleting directory /Users/name/.grails/1.3.1/projects/TekDays/tomcat
Running Grails application..
2010-05-24 21:42:39,559 [main] ERROR context.GrailsContextLoader  - Error executing bootstraps: Failed to invoke Servlet 2.5 getContextPath method
java.lang.IllegalStateException: Failed to invoke Servlet 2.5 getContextPath method
    at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:164)
    at grails.web.container.EmbeddableServer$start.call(Unknown Source)
    at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:159)
    at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy)
    at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:282)
    at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
    at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:150)
    at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy)
    at _GrailsRun_groovy.runInline(_GrailsRun_groovy:116)
    at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy)
    at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:59)
    at RunApp$_run_closure1.doCall(RunApp.groovy:33)
    at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
    at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
    at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
    at gant.Gant.withBuildListeners(Gant.groovy:427)
    at gant.Gant.this$2$withBuildListeners(Gant.groovy)
    at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
    at gant.Gant.dispatch(Gant.groovy:415)
    at gant.Gant.this$2$dispatch(Gant.groovy)
    at gant.Gant.invokeMethod(Gant.groovy)
    at gant.Gant.executeTargets(Gant.groovy:590)
    at gant.Gant.executeTargets(Gant.groovy:589)
Caused by: java.lang.NoSuchMethodException: javax.servlet.ServletContext.getContextPath()
    at java.lang.Class.getMethod(Class.java:1605)
    ... 23 more

I've googled every derivative of "Failed to invoke Servlet 2.5" that I can think of, but have thus far been unable to find anything that helps me understand, yet alone resolve, the error.

Any advice to help me resolve this would be very much appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

醉梦枕江山 2024-09-09 09:33:18

我知道我来晚了一点,但我只是能够在我的机器上解决同样的问题,并且我想我会分享我的结果,以防其他人在谷歌上偶然发现这个问题。

较新版本的 Grails (1.3.7) 包含 groovy 库,因此您无需在项目中引用 groovy jar。当我从 IntelliJ 10 降级到 9 时,我错误地添加了对 Groovy 的引用,认为我需要它。 java.lang.NoSuchMethodError: javax.servlet.ServletContext.getContextPath() 的解释之一是您包含已声明方法的库,这对我来说似乎是问题。

希望这对其他人有帮助!

I know I'm a little late to the party, but I was just able to resolve this same issue on my machine, and thought i'd share my results incase anyone else stumbles across this on Google.

Newer versions of Grails (1.3.7) include the groovy libraries, so you do not need to reference the groovy jars in your project. When I downgraded from IntelliJ 10 to 9, I incorrectly added the reference to Groovy thinking I needed it. One of the explanations for java.lang.NoSuchMethodError: javax.servlet.ServletContext.getContextPath() is that you are including libraries with methods already declared, which appears to have been the problem for me.

Hope this helps someone else!

我不会写诗 2024-09-09 09:33:18

在 /lib 中查找 servlet-api jar 文件并将其删除。

就我而言,我有 servlet-api-2.3.jar,它是由另一个依赖项导入的。该错误明确指出 getContextPath 是 Servlet 2.5 方法。

Look for a servlet-api jar file in /lib and delete it.

In my case I had servlet-api-2.3.jar, which was imported by another dependency. The error specifically states getContextPath is a Servlet 2.5 method.

倾城泪 2024-09-09 09:33:18

这绝对是 CLASSPATH 的问题。对于我来说,由于某种原因它是一个 selenium-server.jar,但对于其他人来说它可能是其他东西。

我会从 shell 窗口中的 CLASSPATH 中删除一个 jar (export CLASSPATH=".;C:/one/less/jar.jar;"),直到找出哪个 jar 导致问题。

It is most definitely an issue with the CLASSPATH. For me it was a selenium-server.jar for some reason, but for someone else it could be something else.

I would delete a jar from the CLASSPATH in my shell window (export CLASSPATH=".;C:/one/less/jar.jar;") until figure out which jar is causing problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文