Question

I have some trouble finding a solution to build different versions of my EAR (with the maven-ear-plugin).

What I would want is to be able to either produce an EAR for production or an EAR for tests, where the test EAR has different ejb-jar.xml deployment descriptors as well as some additional classes from the src/test folders.

The only way I've found so far, is to introduce a profile "blubb" where I override the jar-plugin configuration to include the ejb-jar.xml from src/test/resources as well as some java files, and add a custom suffix to my artifact id (or set a classifier). Then introduce the same profile in my deployment pom, where I depend on the artifacts possessing the suffix, to build a modified EAR.

I've read at various sources, that it is EVIL (i.e. not the Maven way) to produce different jars of the same project depending on profiles. (e.g. at Maven best practice for generating multiple jars with different/filtered classes? or http://blog.sonatype.com/people/2010/01/how-to-create-two-jars-from-one-project-and-why-you-shouldnt/)

So my question is, how can I do this instead? If I build an additional module with my test specific code to include in my deployment conditionally on a profile, I have the problem that my ejb-jar.xml needs to reside in the META-INF directory of exactly that jar file, since my additional "test" module will be contained in a different jar, the ejb-jar.xml will therefore not be applied to the ejbs in my original jar.

Any suggestions, how I could solve this problem (producing a special test ear with modified deployment descriptors and additional classes) the maven way?

Tipps and insights are highly appreciated :-)

Was it helpful?

Solution 2

I found some way to achieve, what I wanted, using the maven-dependency-plugin.

The basic problem was, that no code should have been duplicated, and yet, the same module should be built with additional/replaced content on demand.

The way I did it, was to make a second module, and within declare the module I wanted to modify as sole dependency. Then in the build cycle I added the maven-dependency-plugin with goal "unpack-dependencies" and selected to unpack the original dependency into the target/classes folder at "prepare-package" time.

That way I got a second module, which had the content of the first module, plus some modifications I could then make to the main sources of my adjusted module.

Altogether this is still everything but pretty, in my opinion Maven had its time, but now it's time for a better build tool ;-)

By the way, if anybody knows a more elegant solution, I'm still open... My problem often was, that under no circumstances I wanted to duplicate my configuration or even my code. And it seems that Maven makes this really hard...

OTHER TIPS

The best solution is not to create separated EAR's for test/prod etc from the same . but if you really like to do that you should create two separate ear modules:

 +-- root (pom.xml)
      +--- mod-ejb (pom.xml)
      +--- mod-xxx (pom.xml) 
      +--- mod-ear (pom.xml)
      +--- mot-it-ear (pom.xml)

This means having two EAR modules which can have different descriptors etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top