2

I have a maven (multi-module) project that contains something like an IAction. In this project I have implemented about 50 implementation of different actions. Each Action consists of a MyAction.java and a MyAction.properties file.

I use Java's SPI (java.util.spi) to load all the implementations at runtime. This all works great, but now I want to package each Action into a single jar, so that I end up with 50 jars.

What would be a good way to accomplish this? I don't really want to create a sub-module for each action, as that takes a lot of maintenance.

4
  • you can write a script in bash/batch (dependent on your OS), and launch mvn with some -Dproperty=iterator_index 50 times, then use build-helper-maven-plugin to compile sources from "src/main/java/org/mycompany/${iterator_index}" Commented Jul 3, 2014 at 11:24
  • 1
    No, don't do this. Rather write a small plugin to do this. Otherwise, you make your build quite dependent on a specific environment. Commented Jul 3, 2014 at 11:27
  • 50 jars... and the world's longest classpath. Are you sure you want to do this? Will your client really be picking and choosing actions to deploy on this basis? Commented Jul 3, 2014 at 15:29
  • Projects with more than 50 jars are not uncommon. I use a custom jar class loader that takes care of it, so no class path worries. It is about being able to customize installations and allowing the functionality to be testen on an individual basis. Commented Jul 3, 2014 at 17:17

1 Answer 1

1

You can use the Maven assembly plugin in order to create additional artifacts for building a module. However, note that you need to add these artifacts to your deployment queue once you created them, in case that you do not only want to build these artifacts. This can be achieved by for example using the build-helper-maven-plugin.

However, as for the iteration over 50 elements, you might want to consider writing your own specialized plugin. There are additional plugins that allow the iteration over another plugin, but this will blow up your POM. If a build is therefore very specific, you might therefore consider writing an individual plugin which is specialized on this task. You can do this in pure Java instead of XML and it is not as hard as it sounds. There is documentation and there are default APIs to Maven. And you can check the source code of the named plugins on how to achieve your requirements.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks raphw. I created a mojo that does the work for me. It was a nice learing expercience too :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.