4

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?

palacsint
  • 28,416
  • 10
  • 82
  • 109

1 Answers1

5

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.

Community
  • 1
  • 1
palacsint
  • 28,416
  • 10
  • 82
  • 109
  • Thank you for your time. I installed cdi-api.1.1-20130918 but it now requires javax.inject. I again have this package but not as osgi. Can you explain how you find in particular this package as OSGI bundle. What I did (according to what you wrote) - I checked pom file cdi-api and there javax.inject javax.inject ${atinject.api.version} . But how can I find not simple package but osgi bundle? –  Apr 05 '14 at 07:12
  • What I do now I copy from maven and check manifest.mf if it's bundle. But it's not effective. –  Apr 05 '14 at 07:23
  • Thank you! If you have time, can you look at http://stackoverflow.com/questions/22878449/bootstrap-weld-osgi-version-2-in-se-app-or-bean-manager-not-found ? I need just a direction... –  Apr 05 '14 at 09:36
  • 2
    I already answered it on another question, if you want to use CDI with OSGi use Pax CDI. It's working together with the OSGi foundation to be the reference implementation for CDI in OSGi. – Achim Nierbeck Apr 06 '14 at 08:31
  • @AchimNierbeck: Thanks! I've seen and upvoted that earlirer :-) – palacsint Apr 07 '14 at 07:58
  • @iJava, yes of course, Apache Felix is just the OSGi Framework. It'll work with any OSGi Framework. If interested take a look at Apache Karaf, it's a OSGi - Container. With it it's easy to install for your own use-cases. – Achim Nierbeck Apr 12 '15 at 18:25
  • @ Achim Nierbeck Thank you for you answer. I tried to run karaf bu couldn't - I wrote today to forum (openjdk8 and centos). That's why I went another way. Could you take a look at this question http://stackoverflow.com/questions/29592181/apache-felix-and-org-osgi-for-weld-cdi-constraint-violation –  Apr 12 '15 at 18:42