Hi all, my first time
I am a very new beginner in osgi and  am stating with netbeans maven and
felix
I created the project MyOSGi as a Maven OSGi bundle.
In the src folder I have the com.mycompany.myosgi package which has the
activator and Serviceimpl
In the src folder i have another package called
com.mycompany.myosgi.ServiceInterface which has the interface:

public interface HelloInterface
{
    public void HelloToYou();
}

Here the activator:

package com.mycompany.myosgi;

import java.util.Hashtable;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

public class Activator implements BundleActivator
{
    ServiceImpl x =null;

    public void start(BundleContext context) throws Exception
    {
        x =new ServiceImpl();

        Hashtable props = new Hashtable();
        props.put("description", "This an service impl object");
        context.registerService(ServiceImpl.class.getName(), x, props);

        System.out.println("Service was registered. Hello OSGi World");
    }

    public void stop(BundleContext context) throws Exception
    {
        System.out.println("Goodbye OSGi World");
    }

}

I can compile it without errors and start it in the felix framework:

g! install file:/C:/PROJS/OSGi/felix-framework-4.0.3/MyOSGi-1.0-SNAPSHOT.jar
Bundle ID: 25
g! start 25
Ex1: Service of type com.mycompany.myosgi.ServiceImpl registered.
Service was registered. Hello OSGi World
g!


Then I created another bundle project called MyOSGiClient which has in the
src folder the com.mycompany.myosgiclient package which has the activator
class:

package com.mycompany.myosgiclient;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;


import com.mycompany.myosgi.ServiceInterface.HelloInterface;

public class Activator implements BundleActivator {

    public void start(BundleContext context) throws Exception
    {
        ServiceReference sr  =
context.getServiceReference(HelloInterface.class.getName());
        if(sr != null)
        {
          HelloInterface http = (HelloInterface)context.getService(sr);
          if(http != null)
          {
            http.HelloToYou();
          }
        }
    }

    public void stop(BundleContext context) throws Exception
    {
        // TODO add deactivation code here
    }

}


But the
import com.mycompany.myosgi.ServiceInterface.HelloInterface;    gives me
error because it cant find it


On the "server bundle" I exported both packages.


How can I access server bundle interface type during compile time?


Thanks a lot

Alex

Reply via email to