[OSGi] Utilisation dans un bundle d'un service d'un autre bundle
Bonjour à tous
J'ai un sérieux pb. J'espère que qq'un pourra m'aider (George7 ? ;) ) Comme dit dans le titre, j'utilise OSGI. Je dispose d'un workspace avec 2 projets (un projet Core et un projet plugin)
J'essaie de consommer un service du projet plugin dans mon projet Core mais
Code:
refs = context.getServiceReferences(SimpleShape.class.getName(), null);
me rend toujours null.
Voici mon code (Je simplifie au max. J'espère ne pas oublier de bout de code important) :
PROJET CORE
SimpleShape.java (une simple interface)
Code:
1 2 3 4
| public interface SimpleShape
{
public void draw();
} |
Activator.java ( implements BundleActivator )
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| public void start(final BundleContext context)
{
ServiceTeamTILTTracker m_servicetracker = new ServiceTeamTILTTracker(context);
m_servicetracker.open();
ServiceReference[] refs;
try {
refs = context.getServiceReferences(SimpleShape.class.getName(), null);
if (refs != null)
{
SimpleShape service = (SimpleShape) context.getService(refs[0]);
service.draw();
context.ungetService(refs[0]);
}
else
{
System.out.println("Couldn't find any dictionary service...");
}
} catch (InvalidSyntaxException e) {
e.printStackTrace();
}
} |
PROJET PLUGIN
Activator.java
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| public class Activator implements BundleActivator
{
public void start(BundleContext context)
{
Properties props = new Properties();
context.registerService(SimpleShape.class.getName(), new Square(), props);
System.out.println("Je suis dans mon module WS");
}
public void stop(BundleContext context)
{
}
public class Square implements SimpleShape
{
public void draw()
{
System.out.println("là, je suis en train de drawing");
}
}
} |
Merci beaucoup. Je suis vraiment a court d'idées :(