使用: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 是用过的。也许我需要更改一个设置才能让那个“消失”。
谢谢!