Monday, March 28, 2011

Maven - Hotswap Plugin

For many years I was missing the following feature of Maven: In a multi-module project, when I build a single module in a jar, I want it to be installed into the running environment (app server) seamlessly. During these years I created various scripts for this tasks, why none of them lasted too long: it's very hard to create a generic script, while nongeneric scripts need to be maintained and actually each module must have had its own script. Duh.

Thinking about it, I decided that it should be a Maven plugin, which is very simple - during the install phase, search some predefined location and hotswap the found jars. That's it. So I thought that somebody probably already thought about it and asked a question at Stackoverflow. I received few interesting answers, but not a simple plugin I needed.

So I decided to implement it myself. It took me few hours, since it was my first Maven plugin, so I had some "doing it for the first time" troubles. But finally I did it.

You are welcome to use it, and as always any feedback is appreciated.


cybo said...

Hi Man

I am starting to use the replace-file-plugin and it is doing EXACTLY what I want so thank you.
There is a slight problem:
When I define replaceDirectories (with values inside) instead of replaceDirectory I get the following error:
[ERROR] Failed to execute goal tarlog.maven.plugins:replace-file-plugin:1.0-primo:replace (default) on project common: The parameters 'replaceDirectory' for goal tarlog.maven.plugins:replace-file-plugin:1.0-primo:replace are missing or invalid -> [Help 1]

Somehow I think that the 'replaceDirectories' is not really working...

Can you help me out please ?



Michael Elman said...

Hi cybo,

thank you for your feedback.

It used to work. May be something was changed in the latest versions of Maven.

Anyway, I think I have a workaround for you: define the replaceDirectories with the real values and replaceDirectory with some dummy values.

I think it will work. Cannot grantee it in 100%, so if you are going to check it, please notify me :)


cybo said...

I checked it and once I have replaceDirectory defined it ignores the other replaceDirectories.

Michael Elman said...

Hmmm, strange, according to code it should be an opposite.

Well, another option: you can take the sources and play with it yourself. It's only two classes :)