Thanks Guillaume Nodet , Thanks very much. 
You suggestion is a better choice.
While in my situation, not only the javax.naming package, but a lot of other
packages such as "com.sun.jndi.*" ...etc; it's difficult to list them all
out in the bnd's configurations all out. 
So how about to using Require-Bundle Header? It need not set boot
delegation, and it works like import-package. If so , how can I specify the
system boot loader's name in the Required-Bundle header?  
============================================================================
On Fri, Nov 5, 2010 , Guillaume Nodet [gno...@gmail.com] wrote:

>On Fri, Nov 5, 2010 at 12:02, ext2 <x...@tongtech.com> wrote:
>
>>: Re: How about to to facilitate to use JNDI(boot delegation) in karaf?
>
>>The boot delegation property can be modified in etc/config.properties
>>or overriden in etc/custom.properties.
> I have checked it, but it seems they can only allow I to define additional
> exportable package of boot class loader. But when using these package , I
> must explicit import them in bundle, or else class not found exception
will
> occurs; Here "exportable" means: the package could be visible to others,
but
> the others  must explicit import them, then to use;
>
> But the  org.osgi.framework.bootdelegation could make the exportable
package
> of boot class loader will be visible directly in bundle.
> Here:"visible directly " means: the other bundles need not import it, and
> use the package directly.
>
>
> Do you means I could define the org.osgi.framework.bootdelegation property
> in these files, etc, just add a text like following:
>        org.osgi.framework.bootdelegation=javax.naming, .....
> I have tried, it doesn't works;

The property is already defined in etc/config.properties:

# javax.transaction is needed to avoid class loader constraint
violation when using javax.sql
org.osgi.framework.bootdelegation=org.apache.karaf.jaas.boot,sun.*,com.sun.*
,javax.transaction,javax.transaction.*

If you set it in etc/custom.properties, it should work too, but make
sure you include all the packages above:
org.osgi.framework.bootdelegation=javax.naming,org.apache.karaf.jaas.boot,su
n.*,com.sun.*,javax.transaction,javax.transaction.*

Though, I'm not sure it's a good idea (see below).

>
>>Can you give a bit more detail on how to use JNDI ? I'm not sure to
>>understand why the package is used but not directly referenced.
>
> Ooh,, I am sorry not to express it clearly;
> In my situation, I am using a special jndi which comes from a third part
> product; The third part's jndi is not a bundle, and it's copyright doesn't
> allow I convert it to be a bundle;
> So I can only wrapped the third part's jndi library and my application in
> same bundle, and put the jndi jars in bundle class path.
>
> In my application , I am using the jndi in source code , just like:
>        Context ctx= new InitialContext();
>        ctx.lookup();
> the source code doesn't directly use any class of "javax.naming" package,
so
> the bnd tools cannot find reference to "javax.naming.*" package  according
> by my application's code .  But the third part's jndi will use
> javax.naming(that's say: "used , but not direct referenced in source
code",
> forgive my poor english);
> Finally because the bundle doesn't import all package from javax.naming.*,
> and when the jndi implementation will throw some "javax.naming.*"'s class
> not found exception.

With BND, you can force the inclusion of packages (though BND itself
should be able to discover that one anyway).
You need to not use the * in that case so that BND does not try to
actually detect which packages are used.
So in the import instructions for BND, use:
   <Import-Package>javax.naming,*</Import-Package>
and it should work better.

>
> On Fri, Nov 5, 2010 at 10:35, ext2 <x...@tongtech.com> wrote:
>> Hi:
>>        When  I using jndi in osgi, the "javax.naming" package is
required.
>> But because "javax.naming" package is not direct refereced in the java's
>> source code(; So the generated bundle's Import-Package header doesn't
>> contains "javax.naming" package;
>>        Although the karaf's etc/jre.properties  file could define
>> "javax.naming" to be exportable from boot class loader. But because we
>> doesn't declare import  for "javax.naming" package in bundle,so  a
>> ClassNotFound Exception will still occurs;
>>        So we want the package "javax.naming" which could be used, even
>> there is not import declaration in bundle;
>>        To support this,  I can only define
>> org.osgi.framework.bootdelegation  system property in karaf's startup
>> script;
>>        So I am wondering if karaf could support a configure file which
>> allow we configure the " org.osgi.framework.bootdelegation" ?  if so ,
> it's
>> easy to use control boot delegation;
>>
>>
>>
>
>
>
> --
> Cheers,
> Guillaume Nodet
> ------------------------
> Blog: http://gnodet.blogspot.com/
> ------------------------
> Open Source SOA
> http://fusesource.com
>
>
>



-- 
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/
------------------------
Open Source SOA
http://fusesource.com


Reply via email to