簡體   English   中英

Groovy Grails Tool Suite NoClassDefFoundError在WAR部署上

[英]Groovy Grails Tool Suite NoClassDefFoundError on WAR deployment

使用:GG ver 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”,然后將生產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是用過的。 也許我需要更改設置以使該“消失”。

謝謝!

好的-弄清楚了-足以使其工作...

[關於GG為什么不獨自承擔這些JAR的問題,我仍然感到困惑。]

為了弄清楚哪些JAR文件包含在WAR部署期間報告的缺少類,我只是在dist文件夾中進行了搜索,該文件夾包含安裝了Groovy / Grails v2.2.4(C:\\ grails-2.2.4 \\ dist)。 我使用7zip只是瀏覽JAR。 由於兩個類中都包含“ test”一詞,因此我在JARS中首先使用名稱為“ test”的單詞,然后輕松找到它們。 這就是我找出上面列出的包含這些類的問題中的兩個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

現在,也許您不必全力以赴才能使“刷新依賴項”起作用,但這就是我所做的。 如果我只是做#7,而沒有先做其他事情,那么它將不適用於此版本的GGTS。 現在,WAR會在服務器上正確生成並部署。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM