If you use CDI 1.0, alternatives don't work across different bean archives.
Otherwise (in CDI 1.1+) be careful to activate your alternative as specified here.
The best solution for you is probably to specialize your producer. You'll have to:
- inherit the class containing the original producer method,
- override the producer method and
- annotated it with
@Specializes
.
You'll find all the info on producer specialization in the spec.
If you can't use specialization, your last solution is to create a portable extension that exclude the class containing the original producer from bean discovery (create a observer on ProcessAnnotatedType
event and call the veto()
method on the event) so your producer will not be in conflict with the original one.