【问题标题】:Groovy Grails Tool Suite NoClassDefFoundError on WAR deploymentWAR 部署中的 Groovy Grails Tool Suite NoClassDefFoundError
【发布时间】:2013-10-16 18:28:17
【问题描述】:

使用:GG 版本 2.2.4;和 Groovy/Grails 工具套件版本:3.3.0.RELEASE

问题是:如何将特定的 Grails JAR 放入使用 GGTS 构建的 WAR 中?

作为附带问题,为什么 WAR 不将 JAR 打包到其中?为什么“grails run-app”可以正常工作,但部署 WAR(在开发或生产中)失败?

这是背景:

当我在我的 Windows 7 开发计算机上本地运行“grails run-war”时,它失败了:

2013-10-16 11:36:05,371 [localhost-startStop-1] ERROR context.ContextLoader  - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsApplication' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: grails/test/mixin/domain/DomainClassUnitTestMixin
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:724)
**Caused by: java.lang.NoClassDefFoundError: grails/test/mixin/domain/DomainClassUnitTestMixin**

当我运行“grails war”然后将 Production WAR 部署到我的服务器上的 Tomcat 6 时,我在 catalina.out 中遇到了类似的部署错误:

INFO   | jvm 1    | 2013/10/16 17:03:47 | Oct 16, 2013 5:03:47 PM org.apache.catalina.core.ApplicationContext log
INFO   | jvm 1    | 2013/10/16 17:03:47 | INFO: HTMLManager: start: Starting web application at '/TSWeb-0.1'
INFO   | jvm 1    | 2013/10/16 17:03:48 | Oct 16, 2013 5:03:48 PM org.apache.catalina.core.ApplicationContext log
INFO   | jvm 1    | 2013/10/16 17:03:48 | INFO: Initializing Spring root WebApplicationContext
INFO   | jvm 1    | 2013/10/16 17:03:49 | 2013-10-16 17:03:49,388 [TP-Processor2] ERROR context.ContextLoader  - Context initialization failed
INFO   | jvm 1    | 2013/10/16 17:03:49 | org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsApplication' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: grails/test/mixin/support/GrailsUnitTestMixin
INFO   | jvm 1    | 2013/10/16 17:03:49 |   at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
INFO   | jvm 1    | 2013/10/16 17:03:49 |   at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:311)
INFO   | jvm 1    | 2013/10/16 17:03:49 |   at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:776)
INFO   | jvm 1    | 2013/10/16 17:03:49 |   at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:705)
INFO   | jvm 1    | 2013/10/16 17:03:49 |   at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:898)
INFO   | jvm 1    | 2013/10/16 17:03:49 |   at java.lang.Thread.run(Thread.java:724)
INFO   | jvm 1    | 2013/10/16 17:03:49 | **Caused by: java.lang.NoClassDefFoundError: grails/test/mixin/support/GrailsUnitTestMixin**
INFO   | jvm 1    | 2013/10/16 17:03:49 |   at java.lang.Class.forName(Class.java:270)

我可以在 WAR 内部进行探索,发现 WEB-INF/lib/ 不包含上述两个类所在的 JAR (grails-plugin-testing-2.2.4.jar)。

我试着放了

grails.war.dependencies = [
    "grails-plugin-testing-2.2.4.jar"
    ]

进入 config.groovy,但这不起作用。 WAR 仍然没有包含那个 JAR,我得到了同样的错误。

所以,我只是将 grails-plugin-testing-2.2.4.jar 放入服务器上的 WEB-INF/lib 文件夹并重新部署并验证上述错误消失了,但现在我又遇到了另一个错误服务器:

INFO   | jvm 1    | 2013/10/16 18:34:02 | Oct 16, 2013 6:34:02 PM org.apache.catalina.core.ApplicationContext log
INFO   | jvm 1    | 2013/10/16 18:34:02 | INFO: HTMLManager: start: Starting web application at '/TSWeb-0.1'
INFO   | jvm 1    | 2013/10/16 18:34:03 | Oct 16, 2013 6:34:03 PM org.apache.catalina.core.ApplicationContext log
INFO   | jvm 1    | 2013/10/16 18:34:03 | INFO: Initializing Spring root WebApplicationContext
INFO   | jvm 1    | 2013/10/16 18:34:07 | 2013-10-16 18:34:07,011 [TP-Processor12] ERROR context.ContextLoader  - Context initialization failed
INFO   | jvm 1    | 2013/10/16 18:34:07 | org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pluginManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.RuntimeException: Unable to locate constructor with Class parameter for class org.codehaus.groovy.grails.commons.DefaultGrailsBootstrapClass
INFO   | jvm 1    | 2013/10/16 18:34:07 |   at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
INFO   | jvm 1    | 2013/10/16 18:34:07 |   at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:311)
INFO   | jvm 1    | 2013/10/16 18:34:07 |   at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:776)
INFO   | jvm 1    | 2013/10/16 18:34:07 |   at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:705)
INFO   | jvm 1    | 2013/10/16 18:34:07 |   at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:898)
INFO   | jvm 1    | 2013/10/16 18:34:07 |   at java.lang.Thread.run(Thread.java:724)
INFO   | jvm 1    | 2013/10/16 18:34:07 | Caused by: java.lang.RuntimeException: Unable to locate constructor with Class parameter for class org.codehaus.groovy.grails.commons.DefaultGrailsBootstrapClass
INFO   | jvm 1    | 2013/10/16 18:34:07 |   ... 6 more
INFO   | jvm 1    | 2013/10/16 18:34:07 | Caused by: java.lang.reflect.InvocationTargetException
INFO   | jvm 1    | 2013/10/16 18:34:07 |   ... 6 more
INFO   | jvm 1    | 2013/10/16 18:34:07 | Caused by: java.lang.NoClassDefFoundError: grails/test/GrailsMock
INFO   | jvm 1    | 2013/10/16 18:34:07 |   at java.lang.Class.privateGetDeclaredMethods(Class.java:2521)
INFO   | jvm 1    | 2013/10/16 18:34:07 |   at java.lang.Class.getDeclaredMethods(Class.java:1845)
INFO   | jvm 1    | 2013/10/16 18:34:07 |   ... 6 more
INFO   | jvm 1    | 2013/10/16 18:34:07 | Caused by: java.lang.ClassNotFoundException: grails.test.GrailsMock
INFO   | jvm 1    | 2013/10/16 18:34:07 |   ... 8 more

我将调查第二个错误并在另一个问题中询问它并在此处引用它。 [更新:如果我还将 grails-test-2.2.4.jar 放入服务器上的 WEB-INF/lib 中,此错误就会消失。然后,WAR 部署并运行成功。]

要让这个问题/答案只针对一个主题,我如何将这 2 个 JAR 放入 WAR?

但是,当然,也许有一个解决方案可以解决这两个问题(嘿嘿嘿 - 不太可能但值得一提!)例如,我不知道为什么 grails-plugin-testing-2.2.4 .jar 被使用。也许我需要更改一个设置才能让那个“消失”。

谢谢!

【问题讨论】:

  • 你在 BootStrap.groovy 中有什么东西吗?似乎你的战争有一些依赖于 mixin 的东西,但不应该。
  • 是的,塞尔吉奥。我确实在 BootStrap.groovy 中构建测试数据,并且有 import grails.buildtestdata.mixin.Build。我正在使用 build-test-data 2.0.5 插件。不过还是很好奇。为什么它在开发中与 run-app 一起使用,但它作为 WAR 失败(作为本地开发和服务器上的生产)。但是,当我将 jar 作为依赖项添加到 PROJECTNAME/lib 文件夹中时,它确实解决了我的问题。所以,我正在继续。但是,如果我可以/应该做的其他事情可以让我移除这些罐子并让它工作,我很乐意测试一下。

标签: java tomcat grails groovy


【解决方案1】:

好的 - 想通了 - 足以让它工作......

[仍然对 GG 为何不自己捡起这些 JAR 感到困惑。]

为了弄清楚哪些 JAR 文件包含在 WAR 部署期间报告丢失的类,我只是在包含 grails JAR 的 dist 文件夹中进行了搜索和检查,其中安装了 Groovy/Grails v2.2.4 (C:\grails-2.2 .4\dist)。我使用 7zip 来浏览 JAR。由于这两个类中都有“test”这个词,所以我首先在名称中带有“test”的 JARS 中查找并轻松找到它们。这就是我在上面列出的问题中包含这些类的两个 JAR 文件的方法。

将它们放在服务器上的 WEB-INF/lib 文件夹中,然后成功启动/部署项目确认将它们放在 WAR 中可以解决问题。

为了让它们进入项目并因此在创建 WAR 时加入,我这样做了...

1) run “grails clean” on the project in question
2) close the project (and all others)
3) exit g&g tool suite
4) drag the jar file to your “PROJECTNAME/lib” directory for your project using Windows Explorer.
5) start g&g tool suite
6) open the project
7) right-click on the Project Name and choose Groovy Tools -> Refresh Dependencies

现在,也许您不必跳过所有这些障碍来让 Refresh Dependencies 工作,但这就是我所做的。如果我只做#7,而不先做其他事情,那么它在这个版本的 GGTS 上不起作用。现在,WAR 生成并在服务器上正确部署。

【讨论】:

    猜你喜欢
    • 2015-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多