You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Imóveis Nacionais <im...@gmail.com> on 2013/02/12 13:21:11 UTC

Very beginner question: maven, netbeans. Implementing a client....

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

Re: Very beginner question: maven, netbeans. Implementing a client....

Posted by Ferry Huberts <ma...@hupie.com>.

On 12/02/13 13:21, Imóveis Nacionais wrote:
> Hi all, my first time
> I am a very new beginner in osgi and  am stating with netbeans maven and
> felix


If you're willing to use Eclipse, then bndtools might be something you'd 
want to try.
Follow the tutorial on http://bndtools.org/tutorial.html and you'll be 
up in no time ;-)

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


RE: Very beginner question: maven, netbeans. Implementing a client....

Posted by "Bellinger, Matthew" <Ma...@saabsensis.com>.
Hello Alex,

I am by no means an OSGi expert either, but if I am understanding your code correctly, you are registering the 'ServiceImpl' as a service by it's class name, but asking for the HelloInterface service in your client.  If ServiceImpl implements HelloInterface, then try registering the ServiceImpl object as a HelloInterface service:

context.registerService( HelloInterface.class.getName(), x, props );


~Matt



-----Original Message-----
From: Imóveis Nacionais [mailto:imoveisnacionais@gmail.com] 
Sent: Tuesday, February 12, 2013 7:21 AM
To: users@felix.apache.org
Subject: Very beginner question: maven, netbeans. Implementing a client....

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
-
This message is intended only for the addressee and may contain information that is company confidential or privileged.  Any technical data in this message may be exported only in accordance with the U.S. International Traffic in Arms Regulations (22 CFR Parts 120-130) or the Export Administration Regulations (15 CFR Parts 730-774). Unauthorized use is strictly prohibited and may be unlawful. If you are not the intended recipient, or the person responsible for delivering to the intended recipient, you should not read, copy, disclose or otherwise use this message. If you have received this email in error, please delete it, and advise the sender immediately. 
-                                                                                                                                                                                                                                                       

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Very beginner question: maven, netbeans. Implementing a client....

Posted by Imóveis Nacionais <im...@gmail.com>.
Done!
On client, I have to do RClick on dependencies folder | add | open projects
| and add the bundle server project.
Everythings is fine and works now.! My first OSGi app!! :-)

Thanks you all!

Alex

On Tue, Feb 12, 2013 at 3:15 PM, Bellinger, Matthew <
Matthew.Bellinger@saabsensis.com> wrote:

> You should only have to import the interface (api) that you are trying to
> get the service for.   You don't have to specifically import the
> implementation.
>
> ~Matt
>
> -----Original Message-----
> From: Imóveis Nacionais [mailto:imoveisnacionais@gmail.com]
> Sent: Tuesday, February 12, 2013 10:10 AM
> To: users@felix.apache.org
> Subject: Re: Very beginner question: maven, netbeans. Implementing a
> client....
>
> On Tue, Feb 12, 2013 at 12:47 PM, Holger Hoffstätte <
> holger.hoffstaette@googlemail.com> wrote:
>
> > On 02/12/13 13:21, Imóveis Nacionais wrote:
> > >
> > > How can I access server bundle interface type during compile time?
> > >
> >
> > By adding it into a separate -api jar for (both client and server)
> > compile time. For runtime you can either turn that jar into a bundle
> > as well (so that compile-time structure resembles runtime) or inline
> > the -api into the server bundle and have it exported, so that API and
> > implementation come as one deployment unit. There are advantages and
> > disadvantages to both approaches; neither is "right" or wrong".
> > The first part (api/client/server trifecta) has nothing to do with
> > OSGi and applies just as well to any regular Java project.
> >
> > -h
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> > For additional commands, e-mail: users-help@felix.apache.org
> >
> >
>
> Well, It seems that I have to 'import' the 'server' jar into de client
> bundle project, right?
>
> Alex
> -
> This message is intended only for the addressee and may contain
> information that is company confidential or privileged.  Any technical data
> in this message may be exported only in accordance with the U.S.
> International Traffic in Arms Regulations (22 CFR Parts 120-130) or the
> Export Administration Regulations (15 CFR Parts 730-774). Unauthorized use
> is strictly prohibited and may be unlawful. If you are not the intended
> recipient, or the person responsible for delivering to the intended
> recipient, you should not read, copy, disclose or otherwise use this
> message. If you have received this email in error, please delete it, and
> advise the sender immediately.
> -
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>

RE: Very beginner question: maven, netbeans. Implementing a client....

Posted by "Bellinger, Matthew" <Ma...@saabsensis.com>.
You should only have to import the interface (api) that you are trying to get the service for.   You don't have to specifically import the implementation.

~Matt

-----Original Message-----
From: Imóveis Nacionais [mailto:imoveisnacionais@gmail.com] 
Sent: Tuesday, February 12, 2013 10:10 AM
To: users@felix.apache.org
Subject: Re: Very beginner question: maven, netbeans. Implementing a client....

On Tue, Feb 12, 2013 at 12:47 PM, Holger Hoffstätte < holger.hoffstaette@googlemail.com> wrote:

> On 02/12/13 13:21, Imóveis Nacionais wrote:
> >
> > How can I access server bundle interface type during compile time?
> >
>
> By adding it into a separate -api jar for (both client and server) 
> compile time. For runtime you can either turn that jar into a bundle 
> as well (so that compile-time structure resembles runtime) or inline 
> the -api into the server bundle and have it exported, so that API and 
> implementation come as one deployment unit. There are advantages and 
> disadvantages to both approaches; neither is "right" or wrong".
> The first part (api/client/server trifecta) has nothing to do with 
> OSGi and applies just as well to any regular Java project.
>
> -h
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>

Well, It seems that I have to 'import' the 'server' jar into de client bundle project, right?

Alex
-
This message is intended only for the addressee and may contain information that is company confidential or privileged.  Any technical data in this message may be exported only in accordance with the U.S. International Traffic in Arms Regulations (22 CFR Parts 120-130) or the Export Administration Regulations (15 CFR Parts 730-774). Unauthorized use is strictly prohibited and may be unlawful. If you are not the intended recipient, or the person responsible for delivering to the intended recipient, you should not read, copy, disclose or otherwise use this message. If you have received this email in error, please delete it, and advise the sender immediately. 
-                                                                                                                                                                                                                                                       

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Very beginner question: maven, netbeans. Implementing a client....

Posted by Imóveis Nacionais <im...@gmail.com>.
On Tue, Feb 12, 2013 at 12:47 PM, Holger Hoffstätte <
holger.hoffstaette@googlemail.com> wrote:

> On 02/12/13 13:21, Imóveis Nacionais wrote:
> >
> > How can I access server bundle interface type during compile time?
> >
>
> By adding it into a separate -api jar for (both client and server)
> compile time. For runtime you can either turn that jar into a bundle as
> well (so that compile-time structure resembles runtime) or inline the
> -api into the server bundle and have it exported, so that API and
> implementation come as one deployment unit. There are advantages and
> disadvantages to both approaches; neither is "right" or wrong".
> The first part (api/client/server trifecta) has nothing to do with OSGi
> and applies just as well to any regular Java project.
>
> -h
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>

Well, It seems that I have to 'import' the 'server' jar into de client
bundle project, right?

Alex

Re: Very beginner question: maven, netbeans. Implementing a client....

Posted by Holger Hoffstätte <ho...@googlemail.com>.
On 02/12/13 13:21, Imóveis Nacionais wrote:
> 
> How can I access server bundle interface type during compile time?
> 

By adding it into a separate -api jar for (both client and server)
compile time. For runtime you can either turn that jar into a bundle as
well (so that compile-time structure resembles runtime) or inline the
-api into the server bundle and have it exported, so that API and
implementation come as one deployment unit. There are advantages and
disadvantages to both approaches; neither is "right" or wrong".
The first part (api/client/server trifecta) has nothing to do with OSGi
and applies just as well to any regular Java project.

-h


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Very beginner question: maven, netbeans. Implementing a client....

Posted by Ferry Huberts <ma...@hupie.com>.

On 12/02/13 13:21, Imóveis Nacionais wrote:
> Hi all, my first time

[snip]

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

put the 'server bundle' on the classpath during compile


-- 
Ferry Huberts

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org