powered by Jive Software

Smack-3.2.2 as OSGi bundle

Hi,

I’m trying to use smack-3.2.2 as OSGi bundle.

I’ve developed a simple OSGi bundle, adding to its build path both smack.jar and smackx.jar.

In the bundle manifest, I have added these packages in the section Import-Package

Import-Package: org.osgi.framework, org.jivesoftware.smack, org.jivesoftware.smackx, org.jivesoftware.smackx.pubsub, org.jivesoftware.smackx.commands

In Knopferfish I’ve installed both smack and smackx.

When I start my bundle, it works and the bundle connects correctly to the server, but I have these errors logged in the knopflerfish console:

[stderr] Error! A startup class specified in smack-config.xml could not be loaded: org.jivesoftware.smackx.ServiceDiscoveryManager

[stderr] Error! A startup class specified in smack-config.xml could not be loaded: org.jivesoftware.smackx.XHTMLManager

[stderr] Error! A startup class specified in smack-config.xml could not be loaded: org.jivesoftware.smackx.muc.MultiUserChat

[stderr] Error! A startup class specified in smack-config.xml could not be loaded: org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager

[stderr] Error! A startup class specified in smack-config.xml could not be loaded: org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamManager

[stderr] Error! A startup class specified in smack-config.xml could not be loaded: org.jivesoftware.smackx.filetransfer.FileTransferManager

[stderr] Error! A startup class specified in smack-config.xml could not be loaded: org.jivesoftware.smackx.LastActivityManager

[stderr] Error! A startup class specified in smack-config.xml could not be loaded: org.jivesoftware.smackx.commands.AdHocCommandManager

However, I’ve no errors, also using AdHocCommandManager, anyone knows what is the problem? Is there a way to solve it?

Thanks in advance,

Davide

The way the congiuration loader works is that it attempts to load the config file (and it’s contents) using a list of classloaders. I think you are seeing errors based on the wrong classloader being used to load the configuration file. It still works because another classloader in the list succeeds after the first one fails.

Ideally, this would be reported as warning or info type of messages, but Smack doesn’t have any internal logging mechanism as that would create a dependency where none currently exist. Thus the exceptions that are occurring when the first classloader attempts to load are printed as sys out messages. Not ideal, but that is what you are seeing.

So, in the end you have some benign error messages.

I have entered a task (SMACK-365) to clean this up.

Thanks for the clear explanation,

Davide

Sorry if I re-up the discussion after 8 months, but I have time to work on this question, only now.

I’ve debugged the library and I saw that in SmackConfiguration these classes are not correctly loaded:

[stderr] Error! A startup class specified in smack-config.xml could not be loaded: org.jivesoftware.smackx.ServiceDiscoveryManager

[stderr] Error! A startup class specified in smack-config.xml could not be loaded: org.jivesoftware.smackx.XHTMLManager

[stderr] Error! A startup class specified in smack-config.xml could not be loaded: org.jivesoftware.smackx.muc.MultiUserChat

[stderr] Error! A startup class specified in smack-config.xml could not be loaded: org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager

[stderr] Error! A startup class specified in smack-config.xml could not be loaded: org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamManager

[stderr] Error! A startup class specified in smack-config.xml could not be loaded: org.jivesoftware.smackx.filetransfer.FileTransferManager

[stderr] Error! A startup class specified in smack-config.xml could not be loaded: org.jivesoftware.smackx.LastActivityManager

[stderr] Error! A startup class specified in smack-config.xml could not be loaded: org.jivesoftware.smackx.commands.AdHocCommandManager

SmackConfiguration tries to load the classes using BundleClassLoader, but it doesn’t work and the error messages are printed.

When it tries with the next class loader (sun.misc.Launcher$AppClassLoader), it doesn’t enter in this while cycle:

Enumeration configEnum = classLoader.getResources(“META-INF/smack-config.xml”);

while (configEnum.hasMoreElements()) {

and it exits without loading the classes.

In my Knopflerfish bundle, I have no other errors executing this code:

XMPPConnection.DEBUG_ENABLED =true;

conn1 = new XMPPConnection(“127.0.0.1”);

try {

conn1.connect();

//conn1.loginAnonymously();

conn1.login(“receiver1”, “receiver1”,“Smack”);

conn1.addConnectionListener(this);

System.out.println(conn1.getConnectionID());

}

catch (XMPPException e)

{

e.printStackTrace();

}

PubSubManager manager = new PubSubManager(conn1);

AdHocCommandManager commandManager = AdHocCommandManager.getAddHocCommandsManager(conn1);

but commandManager is null, because AdHocCommandManager is one of the classes not correctly loaded.

Someone has been able to use smack.jar and smackx.jar as Knopflerfish bundles? Is there a workaround?

Thanks in advance,

Davide

I have it working in equinox, but I had to make some changes to the jars. I combined smack and smackx into a single jar, and modified the manifest appropriately to export all the packages. The way smack tries to load classes from the configuration and providers config files does not work well in an OSGi environment. Combining them solves this problem. I also made the debug jar a fragment, which made it work as well.

I will have to try to address this in a future release, as the way it is currently packaged for deployment doesn’t work in OSGi.

thanks! I will try your solution