Pages

Wednesday, March 10, 2010

Binary files and Maven

Recently, I was frustrated while trying to package a Java keystore file from my Maven project to a project archive (tar or zip) using assembly.xml. Somehow, when I used the command:
keytool -keystore cacerts -list
on the certificate keystore inside the tar/zip archive, it would just say that the keystore is invalid. After some search, I found that there is a little setting in the pom.xml which instructs maven not to do any filtering tasks on the files you specify when you execute a maven command.

Lets talk a bit about maven resources filtering. Maven resources documentation has a very good explanation of this feature.  Basically, when you use filtering=true inside your resources tag, the output file in the target folder will contain dynamic values of fields (if it had any). Like, for example:


Suppose, src/main/resources has a Hello.txt, whose contents are Hello ${name}

If filtering is true, ${name} is going to be replaces with the actual value of the property "name" in the pom.xml, when the file is copied to target folder.

Now, even though this filtering is useful, sometimes, we don't want maven to apply this feature on all files in the directory - for example certificate key stores, which are inherently binary in nature. So how do you tackle this? Simple, just use something like this:


Here, I am manually excluding files on which I don't want to apply filters.

Also, in the assembly.xml, I would like to keep line endings, as they might also corrupt these files.
These simple steps will enable you to package any binary content files using Maven.

Saturday, February 27, 2010

So Why This Blog?

I have been toying over the idea of creating a separate blog for my technical wanderings for some time now. Earlier, I had posted some technical posts on my main blog - www.abhishekontheweb.com, but, now, those seem out of place in a blog, which deals with more general stuff, like events, photography, articles (and whatever random thought comes in my mind). As, in the last few years, I have been working on various technologies, especially Java based, I thought of writing about some of the technical ideas that I have been influenced by, technical issues I have been intrigued by, and the upcoming technologies that I am working on. And what better place than to have a new blog just for that.

I would like to put in as much details as possible in my post, else this blog would defeat its purpose.