Search code examples
jakarta-eeglassfishjava-ee-6cdi

Glassfish: Weld won't inject from classes in one jar to classes in an adjacent jar in WEB-INF/lib


I'm having trouble using dependency injection (with CDI/Weld) within libraries used in a war when deploying on Glassfish 3.1. I have two libraries, say:

WEB-INF/lib/library1.jar
WEB-INF/lib/library2.jar

library1 contains a public class, say "InjectMe". Library2 contains another public class, say "InjectionTarget" with an injection site like "@Inject public InjectMe injectMe;" .

Deployment fails with:

WELD-001408 Unsatisfied dependencies for type [InjectMe] with qualifiers [@Default] at injection point [[field] @Inject packagename.InjectionTarget.injectionSite].

Both archives are valid CDI archives with a META-INF/beans.xml .

I've updated weld-osgi-bundle.jar in Glassfish 3.1 and still see the issue.

If I manually unpack library1 and library2, putting their classes directly into WEB-INF/classes, deployment succeeds and injection works as expected.

This is rapidly driving me completely insane. I'm on the verge of restructuring my modules so that the jar subpackages are unpacked with maven-dependency-plugin and archived as a merged jar that I then depend on from my war. That's pretty gruesome, though.

Ideas? Shouldn't this "just work"?


Solution

  • Maybe you are running into this bug?

    https://issues.jboss.org/browse/WELD-846

    http://java.net/jira/browse/GLASSFISH-15721

    http://java.net/jira/browse/GLASSFISH-15735

    I think Glassfish 3.1.1-b04 and newer use Weld 1.1.1.Final which is marked as the fix version for the underlying Weld bug. Testing with that exact version might be enough to confirm it.