WAR部署中的Groovy Grails工具套件NoClassDefFoundError

时间:2013-10-16 18:28:17

标签: java tomcat grails groovy

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

以下是问题:如何在使用GGTS构建的WAR中获得特定的Grails JAR?

作为附带问题,为什么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”然后将生产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部署并成功运行。]

要将此问题/答案保留在一个主题中,如何将这两个JAR纳入WAR?

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

谢谢!

1 个答案:

答案 0 :(得分:0)

好的 - 想出来 - 足以让它发挥作用......

[关于为什么GG没有单独拿起那些JAR,仍然很简单。]

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

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

为了让他们进入Project并因此在创建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

现在,也许你不必通过所有这些箍来让刷新依赖项工作,但这就是我所做的。如果我只做#7,而不先做其他的事情,它就不适用于这个版本的GGTS。现在,WAR在服务器上正确生成和部署。

相关问题