1
votes

I have written an osgi bundle, where i have dependency for a jar(bsf-all.jar), which contains service provider as follows (under META_inf/services/);

bsh.engine.BshScriptEngineFactory
com.sun.script.freemarker.FreeMarkerScriptEngineFactory
com.sun.script.groovy.GroovyScriptEngineFactory
com.sun.script.jacl.JaclScriptEngineFactory
com.sun.script.jaskell.JaskellScriptEngineFactory
com.sun.script.java.JavaScriptEngineFactory
com.sun.phobos.script.javascript.RhinoScriptEngineFactory
com.sun.phobos.script.javascript.EmbeddedRhinoScriptEngineFactory
com.sun.script.jawk.JawkScriptEngineFactory
com.sun.script.jelly.JellyScriptEngineFactory
com.sun.script.jep.JepScriptEngineFactory
com.sun.script.jexl.JexlScriptEngineFactory
com.sun.script.jruby.JRubyScriptEngineFactory
com.sun.script.judo.JudoScriptEngineFactory
com.sun.script.juel.JuelScriptEngineFactory
com.sun.script.jython.JythonScriptEngineFactory
com.sun.script.ognl.OgnlScriptEngineFactory
org.pnuts.scriptapi.PnutsScriptEngineFactory
com.sun.script.scheme.SchemeScriptEngineFactory
com.sun.script.velocity.VelocityScriptEngineFactory
com.sun.script.xpath.XPathScriptEngineFactory
com.sun.script.xslt.XSLTScriptEngineFactory

When i check my bundle state via OSGI console , it is Active and there is no any dependency issue.. But when i try to use it(means after the server up and running) server throws "Class not found" issue ;

java.lang.ClassNotFoundException: com.sun.phobos.script.javascript.RhinoScriptEngineFactory

This particular class is in my dependency jar(bsf-all.jar) and that class is exposed via the service provider.. I suspect there is a class loading issue with OSGi and java service provider..

My pom.xml is as follows;

<dependencies>
        <dependency>
            <groupId>org.apache.bsf</groupId>
            <artifactId>bsf-all</artifactId>
            <version>${bsf.version}</version>
            <optional>true</optional>
        </dependency>
    <dependency>
            <groupId>rhino</groupId>
            <artifactId>js</artifactId>
            <version>1.6R7</version>
            <optional>true</optional>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>

                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                        <Bundle-Name>${project.artifactId}</Bundle-Name>
                        <Export-Package>
                            org.apache.bsf.*,
                            org.mozilla.javascript.*,
                            org.pnuts.scriptapi.*,
                            com.sun.script.*,
                            com.sun.phobos.script.*,
                            bsh.engine.*,
                            javax.script.*,
                        </Export-Package>
                        <Import-Package>
                          com.sun.*                          
                        </Import-Package>
            <DynamicImport-Package>*</DynamicImport-Package>
            <Embed-Dependency>js;scope=compile|runtime;inline=false;</Embed-Dependency>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>

I'm using Equinox OSGi implementation..How can i edit my pom to overcome above issue?

1
is the bsf-all.jar a OSGi-bundle (means: has it a META-INF/MANIFEST.MF file)? - thobens
Service providers won't work in OSGi, but you can use those script engines by manually setting them up ScriptEngineFactory.registerEngineName(String name) - You would be better off trying to get on dependency working at a time. Also rather than embedding everything try wrapping them as individual Jars (i.e. turn each individual dependency into a bundle, see pax-wrap for that). - earcam
"Service providers won't work in OSGi, but you can use those script engines by manually setting them up ScriptEngineFactory.registerEngineName(String name)"..manual registering works fine.. - Ratha

1 Answers

4
votes

I feel that there are too many fundamental errors in this POM to begin speculating about the cause of the CNFE. Your <Export-Package> statement is of most concern. Why are you repackaging and exporting the whole of BSF, Rhino, Phobos and even parts of the JDK inside your bundle??

As I implied in my answer to your earlier question: you are getting bogged down in low-level details without, I think, having a good understanding of what you are trying to achieve at the high level. Therefore even if somebody posts an answer that gets you past this particular issue, you will still not have a working architecture.

Please step back and describe at a high level what you are trying to achieve and why. Then we can offer a solution based on good OSGi practices.