; last updated - 3 minutes read

These days we had some difficulties updating the libraries we used. We had to update them pretty often, sometimes twice a week. So I was looking for a neat way to update the libraries on my colleagues' computers without blocking their work.

Both Tomcat and Eclipse open the library file, so you cannot delete or update the files without stopping both Tomcat and Eclipse.

In most cases, it is easy to update your libraries. Just put them in your applications WEB-INF/lib folder, and you are done. Put the libraries under version control, and they are distributed automatically to every member of your team. If you use Maven, it is even more straightforward. Just update the pom.xml, and the libraries are updated automatically.

Unfortunately, this was not an option. We use Liferay as a portal server. The duration of the deployment seems to explode as the war-files grow. I guess the time grows proportional to the square or cube of file size. Don't take my word for it, but it feels that way. Bottom line is: it does grow, and I am impatient.

An efficient strategy to keep the war file small is to put every library into Liferay's global lib folder. However, how do you distribute new versions or new libraries?

Our solution is to create a new Eclipse project "global libraries." Check every library in the "Order and Export" dialog. We put this project under source code control, so it is simple to distribute updated libraries. Every other project has to import this project.

To distribute these libraries to Liferay, we used build files. We already had to use build files, so we just added a few lines. Copy the libraries to the folder - say - liferay/tomcat/lib/ourExt. Of course, this is not a Liferay folder. You have to teach Liferay to use this folder by opening the file liferay/tomcat/conf/catalina.properties. Find the line starting with "common.loader" (in my case line 47). This line is a list of directories Tomcat uses to find its global libraries. Just add ,${catalina.home}/lib/ourExt/*.jar.

Obviously, this trick applies to Tomcat based Liferay distributions only. If you use another distribution, I guess the idea works as well, but you have to use different files and directories.

Now your build script can synchronize the two libraries folders. Note that you have to stop Liferay to be able to update the libraries.

The only remaining problem is that you cannot update the libraries within Eclipse. "Team update" won't work because Eclipse uses the libraries. The only solution I found is closing Eclipse and updating the entire project outside Eclipse.


Comments