Question

I use Apache Felix and weld-osgi for a Java SE application. The problem is that in injected bean I use @ApplicationScoped from package javax.enterprise.context.ApplicationScoped. But there is no such package in weld-osgi-bundle-2.1.2.Final.

This package exist in weld-se but it's not in the OSGi bundle. How can I solve this problem?

Was it helpful?

Solution

I would try running the following dependency as separate bundle:

<dependency>
    <groupId>javax.enterprise</groupId>
    <artifactId>cdi-api</artifactId>
    <version>1.1-20130918</version>
</dependency>

(Maven Central link)

Be careful, you need version 1.1-20130918. Version 1.1 does not have OSGi headers in the MANIFEST.MF. You can unzip the jar and check the META-INF/MANIFEST.MF file for OSGi headers like Bundle-ManifestVersion and Bundle-SymbolicName. You can also check here the required packages of that bundle, it's in the Import-Packages header.

How to figure out

Check the dependencies of weld-osgi-bundle on Maven Central (or in its pom.xml). It contains the following:

<dependency>
    <groupId>org.jboss.weld</groupId>
    <artifactId>weld-api</artifactId>
</dependency>

This weld-api refers to the cdi-api above which contains the missing annotation:

<dependency>
    <groupId>javax.enterprise</groupId>
    <artifactId>cdi-api</artifactId>
</dependency>

Another way is pressing F3 (Open Declaration) in Eclipse while the cursor in the ApplicationScoped annotation then in the Project Explorer View enable the Link with Editor and it will show that ApplicationScoped.class is inside the cdi-api-1.1.jar.

Finding OSGi version of another jars

You probably need more bundles than this one (transitive dependencies or it was only the first one which stopped the installation). Not all well-known jar has OSGi headers, like the following one:

<dependency>
    <groupId>javax.inject</groupId>
    <artifactId>javax.inject</artifactId>
    <version>1</version>
</dependency>

In that case search for the group id on Maven Central. Two results which contain the javax.inject package and have OSGi headers:

If you can't find anything you can convert any jar to OSGi bundle by hand. Actually, you can do this with the weld-se.jar but installing dependencies separately looks cleaner.

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