injecteer
injecteer

Reputation: 20707

Building a slim war in Grails 3.1.7

I want to assemble a war file w/o any jar files (I copied them to my /opt/tomcat8/lib dir already).

I read about -nojars options, but it's not available for Grails 3.1.7.

Then I tried customizing my build.gradle:

war{
  rootSpec.exclude "**/*.jar"
}

and the resulting war indeed became very small ~1 MB. Although when I deploy it into a tomcat and call the http://host:8080/, I'm getting

javax.servlet.ServletException: Could not resolve view with name '/error' in servlet with name 'grailsDispatcherServlet' org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1229) org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1029) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:973) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:895) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967)

What's the proper way to build the slim war's?

SIDE NOTE:

The application contains only of a couple of domain classes and scaffolded controllers. No views were modified after grails create-app

Upvotes: 3

Views: 773

Answers (2)

injecteer
injecteer

Reputation: 20707

As a follow-up, I created an issue, and as Graeme couldn't reproduce the behavior, the ticket was closed. Although for me it still didn't work.

So I came up with a simple workaround, which is not that elegant as my original wish, but is very straight-forward:

  1. unzip the slim .war-file into ~/ROOT/

  2. copy all Grails 3.1.11 + plugins dependency jars into ~/ROOT/WEB-INF/lib

Note: sym-link DID NOT work...

  1. move the ~/ROOT folder to /opt/tomcat/webapps

Thus, the war file I create on my build-machine and send over to prod remains thin

Upvotes: 0

Loucher
Loucher

Reputation: 316

First in your build.gradle you have to change scope of all compile dependencies to provided. For some reason runtime dependencies must be kept for Grails to work (i don't have explanation for that yet).

For example compile "org.grails:grails-core" will be changed to provided "org.grails:grails-core"

This will stop gradle to package libs to WEB-INF/lib, but it will now create new folder WEB-INF/lib-provided with all dependencies. These libs should not be visible to 'external' application server, but are required for archive (in this case war) execution. This is done by bootRepackage task.

You can disable bootRepackage task by adding this command to your build.gradle:

bootRepackage.enabled = false

Now your war task should create archive without any jars.

Upvotes: 3

Related Questions