Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid copying 40M of java lib's within a WAR when the WAR's size is 41M?

At the moment my build process consists of repackaging the war file with all required java libraries under WEB-INF/lib and then copying the war file to development/demo/production server to be redeployed by tomcat.

The packaged war file's size is about 41M and it has at the moment something like 40M of external java libraries. There has to be a better way. How have you solved this issue?

My development machine is a windows box with Eclipse as my IDE and Ant as my build tool. The servers are all linux boxes with Tomcat 5.5.

Should I maybe add the jar files to the war package at server side?

like image 811
kosoant Avatar asked Apr 06 '09 17:04

kosoant


4 Answers

I can see what you are saying, and have had the same frustration with some of our webapps, but for consistency sake, I would suggest you keep things as they are. If copying the libraries to the tomcat/lib directory you may run into issues with the system classpath vs. the webapp classpath.

By keeping things as they are you are sure you are deploying the same stuff in development/demo as you are in production. Life sucks when you are manually tweaking stuff in production, or you have some crazy error because you forgot to update XYZ.jar from version 1.6 to 1.6.1_b33 in production and now it's behaving differently than what you believe is the exact same code on demo.

When working with something vital enough to have dev/demo/production systems, I think consistency is much more of an issue than .war file size.

like image 185
digitaljoel Avatar answered Nov 14 '22 21:11

digitaljoel


We use the rsync tool for this (in our case, using cygwin under windows) to copy the deployments to the servers (which run linux). We use exploded WAR/EAR files (i.e. a directory structure called MyApp.war rather than a zip file called MyApp.war), rsync will only transfer the files that have changed.

In general use, rsync will transfer our 30-40 megabyte exploded EARs in about 5 seconds.

like image 44
skaffman Avatar answered Nov 14 '22 22:11

skaffman


Tomcat has a shared/lib directory, which is the proper place for global application dependencies. However, these will be visible to all applications, which will affect dependency management and may have consequences for things like static variables. I'm not sure if you can configure anything better in Tomcat.

An alternative is to switch to a more sophisticated web container. For example, WebSphere Application Server Community Edition (a blue-washed version of Geronimo) supports per-asset libraries. Other free and commercial servers support this, too. I know WebSphere Application Server does and I'm pretty sure you can do it in Glassfish.

like image 27
McDowell Avatar answered Nov 14 '22 22:11

McDowell


@McDowell, when mentioning those J2EE servers, you should precise that they are J2EE servers(servlet container + the rest).

Like @digitaljoel, I suggest to keep things like they are. It looks like you haven't done much web application deployment yet. The issues that you'll have are not worth the price(version conflicts, deployment errors, etc.).

like image 43
John Doe Avatar answered Nov 14 '22 23:11

John Doe