Try setting the contextclassloader to the classloader of your bundle i.e.,
ClassLoader ccl = Thread.currentThread().getContextClassLoader();
try
{
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
// do context init
}
finally
{
Thread.currentThread().setContextClassLoader(ccl);
}
That should do the trick.
regards,
Karl
On Mon, Mar 10, 2008 at 4:13 PM, Luca Ballestin
<[EMAIL PROTECTED]> wrote:
> Hi
>
> I'm trying to make a bundle that communicate with a jms server (jboss
> messaging).
>
> I've builded a small stand-alone test client, and everything works fine.
>
> When I put all libraries and code in a bundle, i get the following
> exception:
>
> javax.naming.NoInitialContextException: Cannot instantiate class:
> org.jnp.interfaces.NamingContextFactory [Root exception is
> java.lang.ClassNotFoundException: org/jnp/interfaces/NamingContextFactory]
> at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
> at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
> at javax.naming.InitialContext.init(Unknown Source)
> at javax.naming.InitialContext.<init>(Unknown Source)
> at it.necsy.voip.impl.message.JmsSenderImpl.<init>(JmsSenderImpl.java
> :42)
> at it.necsy.voip.impl.message.MessageActivator.start(
> MessageActivator.java:135)
> at org.apache.felix.framework.util.SecureAction$Actions.run(
> SecureAction.java:869)
> at java.security.AccessController.doPrivileged(Native Method)
> at org.apache.felix.framework.util.SecureAction.startActivator(
> SecureAction.java:586)
> at org.apache.felix.framework.Felix._startBundle(Felix.java:1535)
> at org.apache.felix.framework.Felix.startBundle(Felix.java:1469)
> at org.apache.felix.framework.Felix.setFrameworkStartLevel(Felix.java
> :1064)
> at org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java
> :258)
> at java.lang.Thread.run(Unknown Source)
> Caused by: java.lang.ClassNotFoundException:
> org/jnp/interfaces/NamingContextFactory
> at java.lang.Class.forName0(Native Method)
> at java.lang.Class.forName(Unknown Source)
> at com.sun.naming.internal.VersionHelper12.loadClass(Unknown Source)
> ... 14 more
>
>
> I've opened the bundle, and the class
> org.jnp.interfaces.NamingContextFactory is in the rigth place.
>
>
>
>
> The manifest is:
>
> Bundle-Activator: ####.MessageActivator
> Bundle-Vendor: ####
> Bundle-Version: 0.0.1
> Import-Package: org.osgi.framework,
> javax.naming.spi,
> javax.naming
> Export-Package: ####.message
>
>
>
>
>
>
> The code that throws the exception is
>
> try {
> Hashtable<String, Object> env = new Hashtable<String, Object>();
> env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "
> org.jnp.interfaces.NamingContextFactory");
> env.put(javax.naming.Context.URL_PKG_PREFIXES, "
> org.jboss.naming:org.jnp.interfaces");
> env.put(javax.naming.Context.PROVIDER_URL,
> "jnp://localhost:1099");
> initialContext = new InitialContext(env);
> } catch (NamingException e) {
> logger.error("Could not create JNDI API ",e);
> }
>
>
> Is something misplaced?
>
> If it is possible, i would like to keep the jms libraries inside of the
> bundle.
>
> Thanks
>
> Luca
>
--
Karl Pauls
[EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]