5

I am having a problem running grails generated war file on tomcat7. If/when I run the same app with grails run-app all is good and in the proper working order. The exception I get while running tomcat7 and deployed war:

2014-08-20 09:17:28,933 [http-bio-127.0.0.1-8080-exec-7] ERROR errors.GrailsExceptionResolver  - ClassNotFoundException occurred when processing request: [GET] /
jline.console.history.History. Stacktrace follows:
java.lang.ClassNotFoundException: jline.console.history.History
    at org.codehaus.plugin.swagger.builder.SwaggerDocsBuilder.buildApiDeclarations(SwaggerDocsBuilder.groovy:71)
    at org.codehaus.plugin.swagger.builder.SwaggerDocsBuilder.rebuild(SwaggerDocsBuilder.groovy:48)
    at org.codehaus.plugin.swagger.builder.SwaggerDocsBuilder.build(SwaggerDocsBuilder.groovy:36)
    at org.codehaus.grails.plugins.swaggerapidocs.SwaggerApiDocsController.resources(SwaggerApiDocsController.groovy:21)
    at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:198)
    at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
    at com.brandseye.cors.CorsFilter.doFilter(CorsFilter.java:82)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

Line 71 of SwaggerDocsBuilder.groovy

rules = new BuildPathMap().build(grailsApp)

and BuildPathMap extends

import org.codehaus.groovy.grails.web.mapping.reporting.AnsiConsoleUrlMappingsRenderer
class BuildPathMap extends AnsiConsoleUrlMappingsRenderer {

my guess is AnsiConsoleUrlMappingsRenderer somehow depends on jline.console.history.History but then why is it missing from the war file? Is there something that can be done during the war generation to ensure that ll dependencies are properly packaged?

Nisse Engström
  • 4,555
  • 22
  • 24
  • 38
ash
  • 661
  • 3
  • 8

3 Answers3

3

Its a bug in grails.

https://jira.grails.org/browse/GRAILS-8532

could fix this with a workaround adding the following snippet to BuildConfig.groovy:

grails.war.resources = { stagingDir, args ->
    copy(todir: "${stagingDir}/WEB-INF/lib", flatten: "true") {
        fileset(dir: "${grailsHome}/lib", includes: "**/jline-*.jar, **/jansi-*.jar")
    }
}
Milind J
  • 529
  • 5
  • 10
2

Not sure if this is the best solution, but I was able to get around this problem by explicitly adding a jLine dependency in BuildConfig.groovy:

runtime 'jline:jline:2.12'

I did not see this error with Grails 2.5.1, but did with Grails 2.5.4. Seems like a bug.

augustearth
  • 281
  • 2
  • 10
0

Is your Tomcat configured to run an unpacked or packed war. Development runs as an unpacked war so commands like servlet.getRealPath() return a valid value when running that on a packed war the Tomcat servlet container returns null. In the server.xml search for unpackWARs attribute.

  <Host name="localhost"  appBase="webapps"
        unpackWARs="false" autoDeploy="false">

Also some dependencies are added for you when running in development and you need to specify them in the BuildConfig.groovy otherwise they may not be available in the war.

Joe
  • 951
  • 6
  • 13
  • "Also some dependencies are added for you when running in development and you need to specify them in the BuildConfig.groovy otherwise they may not be available in the war." - this is something that I find odd but it sure seems like it is the case. Is there a way to prevent this from happening, so in my development I can prevent problems that might occur in production? – ash Aug 20 '14 at 17:18