The size of a normal Grails WAR file is at least 20MB. The reason is the big list of JAR files which are included in the WEB-INF/lib directory. To exclude all JAR files from the WAR file we can use the command-line argument -nojars. This will even exclude JAR files provided by Grails plugins. The complete command to create the WAR file is:
$ grails war -nojars
We now have a much smaller WAR file (about 200KB for an empty Grails application): a skinny war. This scenario is useful if for example our upload speed is slow. Uploading 20MB can take up to minutes with an ASDL connection. So for a first deployment we can upload the complete WAR file, but for following deployments we can use the small WAR file. Of course we must keep in mind we didn't add new plugins to the application with JAR files, because they will not be added to the WAR file.
3 comments:
Will the -nojars eliminate ALL of the jars? I have a fairly small app but I am using some of the Apache collections classes which means I would expect that I will need some subset of the jars?
What's the best way to handle this?
@Mike Miller: yes all jars are eliminated from the WAR file. This means you must put the jar files you need in the classpath of the JEE container yourself.
Another option is to define a new closure in BuildConfig.groovy with the name grails.war.dependencies. We can define which libraries we want in our WAR file. These files (and any jar files from the plugins) are now copied to the WAR file. We must leave out the -nojars option this time.
Hi,
i tried with running "grails war -nojars"
I was getting errors :
srinath@srinath-laptop:~/Grails-apps/public_associations_jan09$ grails war -nojars
Welcome to Grails 1.1.2 - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: /home/srinath/grails-1.1.2
Base Directory: /home/srinath/Grails-apps/public_associations_jan09
Running script /home/srinath/grails-1.1.2/scripts/War.groovy
Environment set to production
Warning, target causing name overwriting of name startLogging
Searching for portlets: file:/home/srinath/Grails-apps/public_associations_jan09/grails-app/portlets/**/*Portlet.groovy ...
Generating portlet.xml - 1 portlets found ...
[mkdir] Created dir: /home/srinath/.grails/1.1.2/projects/public_associations_jan09/stage
[copy] Copying 93 files to /home/srinath/.grails/1.1.2/projects/public_associations_jan09/stage
[copy] Copied 22 empty directories to 1 empty directory under /home/srinath/.grails/1.1.2/projects/public_associations_jan09/stage
[copy] Copying 25 files to /home/srinath/.grails/1.1.2/projects/public_associations_jan09/stage/WEB-INF/grails-app
[copy] Copying 108 files to /home/srinath/.grails/1.1.2/projects/public_associations_jan09/stage/WEB-INF/classes
[mkdir] Created dir: /home/srinath/.grails/1.1.2/projects/public_associations_jan09/stage/WEB-INF/spring
[mkdir] Created dir: /home/srinath/.grails/1.1.2/projects/public_associations_jan09/stage/WEB-INF/templates/scaffolding
[copy] Copying 1 file to /home/srinath/.grails/1.1.2/projects/public_associations_jan09/stage/WEB-INF
[delete] Deleting: /home/srinath/.grails/1.1.2/projects/public_associations_jan09/resources/web.xml
[propertyfile] Updating property file: /home/srinath/.grails/1.1.2/projects/public_associations_jan09/stage/WEB-INF/classes/application.properties
[mkdir] Created dir: /home/srinath/.grails/1.1.2/projects/public_associations_jan09/stage/WEB-INF/plugins/portlets-0.7
[copy] Copying 2 files to /home/srinath/.grails/1.1.2/projects/public_associations_jan09/stage/WEB-INF/plugins/portlets-0.7
[mkdir] Created dir: /home/srinath/.grails/1.1.2/projects/public_associations_jan09/stage/WEB-INF/plugins/hibernate-1.1.2
[copy] Copying 1 file to /home/srinath/.grails/1.1.2/projects/public_associations_jan09/stage/WEB-INF/plugins/hibernate-1.1.2
[mkdir] Created dir: /home/srinath/.grails/1.1.2/projects/public_associations_jan09/stage/WEB-INF/plugins/portlets-liferay-0.1
[copy] Copying 1 file to /home/srinath/.grails/1.1.2/projects/public_associations_jan09/stage/WEB-INF/plugins/portlets-liferay-0.1
[delete] Deleting directory /home/srinath/.grails/1.1.2/projects/public_associations_jan09/stage
Error executing script War: : Directory does not exist:/home/srinath/.grails/1.1.2/projects/public_associations_jan09/stage/WEB-INF/lib
gant.TargetExecutionException: : Directory does not exist:/home/srinath/.grails/1.1.2/projects/public_associations_jan09/stage/WEB-INF/lib
Post a Comment