Making .war smaller - grails

There are several tutorials and even some posts here about shrinking .war files. However, the most common technique (to include grails.war.resources = {} in Config.groovy) does not seem to work for me. No matter what, grails dumps everything into the war file making a 25meg .war. Has this functionality changed? Grails 1.3.4

Im on 1.2.0
grails war --nojars
creates a war with no jars.
You have to make sure your jars are properly installed on wherever you are deploying, so
$tomcat/shared/lib
for tomcat.

For tomcat6 and later remember to update your catalina.properties file:
shared.loader=${catalina.home}/yourDirectoryName/*.jar
You will need to ensure that ${catalina.home}/yourDirectoryName exists and that it contains all the grails WEB-INF/lib jars in it.

Related

How to exclude grails plugin jar from war file

Grails 3.2.5. Build.gradle has mail plugin:
compile "org.grails.plugins:mail:2.0.0.RC6"
In deploying a war to production I need to remove javax.mail-1.5.6.jar from WEB-INF/lib since that jar must be in the Tomcat lib when using a JNDI mail resource. So how do I keep the mail plugin but remove the offending jar file from the war? I knew how to do this in Grails 2.x. Via the gradle war task in build.gradle I have tried to exclude the file (doesn't work - the jar drifts in from a plugin somehow), and have tried to filter the file out. When I build the war I get two files - "app-0.1.war" and "app-0.1.war.original". The "original" file has the WEB-INF/lib/javax.mail jar filtered out, but the real, complete war still has it.
So how do I prevent that plugin jar from getting into the war file? Thanks.
One way to do it is with something like this:
war {
rootSpec.exclude '**/javax.mail*.jar'
}
(you may need to adjust depending on whether or not you want to also exclude the javax.mail-api jar file along with the javax.mail jar)
See https://github.com/jeffbrown/excludejar/blob/67734ac0c65cdbead468f1e65bcfc29041cd2279/build.gradle#L70-L72

rebuilding grails war file from ant

Grails war file are very big since they contains all the jars and plugins, this can be problematic when deploying on a virtual server since every small change I have to resend the whole war.
I found out that you can build the war file through ant directly on the server and send only the class files which are much smaller in size.
Can anyone tell me practically how this can be done?
Can I modify an existing war by changing some only some class files ?
Thanks,
Dany
You should be able to hook into eventWarStart and customize the war.
See http://www.anyware.co.uk/2005/2009/01/21/excluding-files-from-a-war-with-grails-the-right-way/

Grails picking old version jars(previous used) also, in 'test war' creation

I used yesterday itext-2.0.8 and today i changed to itext-2.1.7. even it is picking 2.0.8 into war file also two versions of itext jars are coming in war file. Now, there is no reference in pom or BuildConfig regarding 2.0.8, even it adding in war file.
Why it picking old referred jars and what bases it selecting which jars need to go for war file.
What should i do to eliminate them.
i deleted target folder and i run grails clean, even same output.
i think, i have to manually delete the all itext-2.0.8 in maven repo(.m2) and grails repo(.grails).
please give me your valuable suggestions please

Grails + Tomcat6 + Multiple Instances + Shared Lib Folder

I've got a Tomcat6 server that runs multiple Instances for two separate grail apps.
When I compile my WAR file for deployment normally
run-app -Dgrails.env=production war test.war
It deploys correctly and everything works as it is suppose too.
The problem is, I don't want the JAR files included in my WAR.
So I use the following command line instead
run-app -Dgrails.env=production war test.war --nojars
Now when my grails app deploys (it doesn't) I get a java.lang.NoSuchMethodError
I have copied the lib folder (from my initial test.war) to the following locations
${catalina.base}/shared/lib
${catalina.home}/shared/lib
${catalina.home}/lib
None of these work.
My catalina.properties all point to the correct locations.
Any ideas?
A few ideas:
BuildConfig.groovy has inherits global, which has the app inherit all of the grails/plugins dependencies. If you change this, it may affect both your build and packaging - plus I have yet to encounter any documentation on what type of other things you can do with the inherits DSL
Grails deployment documentation suggests there is a way to customize which dependencies make it into the war file: http://grails.org/doc/latest/guide/17.%20Deployment.html
Event hooks give you access to provide a closure routine into various stages of the grails lifecycle. Can it strip out framework jars from the final war? Haven't tried that either - only using it to re-write various config files for additional envrionment configuration. However it does look like packaging events are exposed to this API:
http://grails.org/doc/latest/guide/4.%20The%20Command%20Line.html

where are grails libs specified

I recently upgraded a project to Grails 1.3.5. This deleted everything in the /lib dir, though the project continues to work, so I guess the way dependencies are specified (and the location they're stored) has changed. I want to remove some libs that I'm no longer using, but can't do this until I find where the dependencies are specified.
Thanks,
Don
I'm surprised that anything was deleted from your lib directory - that shouldn't happen.
Dependencies are registered in BuildConfig.groovy in your app and in the plugins that work with Grails 1.2 and above. Older plugins will continue to have jars in their lib directories which will be added to the classpath, and you can still do the same. Obviously it's best to use the dependency management if possible so you have just the one copy of the jar in your Ivy cache instead of one for every project on your machine.
You can run grails dependency-report to generate Ivy reports to see what's managed by Ivy in each environment. These will end up in target/dependency-report and there's no index file, so just open any of the .html files and you can navigate to the others from there, e.g. target/dependency-report/org.grails.internal-{appname}-runtime.html.

Resources