Using Reflections in an OSGi Container

763 views
Skip to first unread message

onyx.bl...@gmail.com

unread,
Aug 22, 2013, 10:44:42 AM8/22/13
to google-code...@googlegroups.com
I'm trying to use reflections in an Apache Felix/Sling environment. I first tried just to use the dependency in my pom and embedding the jar. There all the transient dependencies were missing. So I tried it again with the uberjar, by adding it to the classpath. But still it seems some dependencies are missing:
<plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <extensions>true</extensions>
    <configuration>
        <instructions>
            <Bundle-SymbolicName>com.ic.ic-base-bundle</Bundle-SymbolicName>
            <Bundle-ClassPath>
                .,
                lib/reflections-0.9.9-RC1-uberjar.jar
            </Bundle-ClassPath>
        </instructions>
    </configuration>
</plugin>
 
Am I missing something? Do I need to export all the missing dependencies?

Or even better is there an OSGi enabled bundle of reflections available somewhere?

onyx.bl...@gmail.com

unread,
Aug 23, 2013, 3:04:17 AM8/23/13
to google-code...@googlegroups.com, onyx.bl...@gmail.com
I played around with the pom and now at least I am able to instantiate Reflections, though it doesn't find any classes.
Here is what I've changed in the pom (no longer using the uberjar, but separate dependencies and some excludes for the import):

<plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <extensions>true</extensions>
    <configuration>
        <instructions>
            <Bundle-SymbolicName>com.ic.ic-base-bundle</Bundle-SymbolicName>
            <Import-Package>
                !com.google.gson.*;resolution=optional,
                !com.sun.jdi.*;resolution=optional,
                !sun.misc.*;resolution=optional,
                !org.apache.commons.vfs2.*;resolution=optional,
                !org.dom4j.*;resolution=optional,
                *
            </Import-Package>
            <Embed-Dependency>
                reflections;scope=provided,
                guava;scope=runtime,
                javassist;scope=runtime
            </Embed-Dependency>
        </instructions>
    </configuration>
</plugin>

Do I still need one of the other dependencies still? I was following the ClasspathNotes: http://code.google.com/p/reflections/wiki/ClasspathNotes and got the dependencies from the pom.xml at http://code.google.com/p/reflections/source/browse/trunk/reflections/pom.xml

onyx.bl...@gmail.com

unread,
Aug 23, 2013, 4:35:57 AM8/23/13
to google-code...@googlegroups.com, onyx.bl...@gmail.com
Found the problem, but no solution so far. In the OSGi environment, the URLs look a bit different when retrieving it with ClasspathHelper.forPackage(): bundle://308.62:1/
and this throws an exception in the method public void scan(URL url)

So I think I have to wait until someone adds OSGi support to the library as I can't spend more time on this and need to find another solution.

vaishali....@gmail.com

unread,
Jan 15, 2014, 2:54:31 PM1/15/14
to google-code...@googlegroups.com, onyx.bl...@gmail.com
NO Rreflections does not work in OSGI environment because of the issue listed in above thread . Any idea is there is plan to add OSGI support? The Reflections seem to be using URL class loader and that doesnt work in OSGI.
I also need OSGI support, so would appreciate answer.

On Saturday, August 24, 2013 4:03:14 AM UTC-7, mamo wrote:

Vaishali Mithbaokar

unread,
Jan 15, 2014, 4:19:16 PM1/15/14
to google-code...@googlegroups.com, onyx.bl...@gmail.com
which version it is supported?I tried reflections-0.9.9-RC1, does it have the support? or do we need to download sources of latest from reflections and build it ourselves? Or do you have the jar which has OSGI support?


On Saturday, August 24, 2013 4:03:14 AM UTC-7, mamo wrote:
Any inputs on that?

On Friday, August 23, 2013 11:35:57 AM UTC+3, onyx.bl...@gmail.com wrote:
Message has been deleted

lukasz....@gmail.com

unread,
Aug 5, 2015, 9:45:33 AM8/5/15
to google-code-reflections, onyx.bl...@gmail.com
ServiceMix bundles provides a "fixed" version of reflections library which does work under OSGi environment.


Kind regards,
Lukasz
Reply all
Reply to author
Forward
0 new messages