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

时间:2010-05-25 03:48:39

标签: grails installation osx-snow-leopard

[UPDATE]

显然我不是唯一有这个问题的人 - 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中运行而不是从终端运行呢?

[/ UPDATE]

我正试图在Snow Leopard机器上安装Grails。我按照所有grails.com安装说明进行操作,并尝试从Grails开始应用程序:Dave Klein的快速入门指南。我运行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”的所有衍生产品,但到目前为止还没有找到任何可以帮助我理解但却单独解决错误的内容。

非常感谢任何帮助我解决此问题的建议!

3 个答案:

答案 0 :(得分:1)

我知道我参加派对的时间有点晚了,但我只能在我的机器上解决同样的问题,并且认为我会分享我的结果,因为其他人在Google上偶然发现了这一点。

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

希望这有助于其他人!

答案 1 :(得分:0)

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

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

答案 2 :(得分:0)

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

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

相关问题