You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Guillaume Nodet <gn...@gmail.com> on 2010/11/05 11:04:46 UTC

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.
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.

On Fri, Nov 5, 2010 at 10:35, ext2 <xu...@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

Re: How about to to facilitate to use JNDI(boot delegation) in karaf?

Posted by Guillaume Nodet <gn...@gmail.com>.
Also, Aries provides a JNDI / OSGi integration which you may want to
look at depending on your needs.

On Fri, Nov 5, 2010 at 14:24, Achim Nierbeck <Ac...@ptv.de> wrote:
> Sorry, to interrupt, but Require-Bundle is really bad practice :(
>
>
> Just one side node from me, I once had also an issue with JNDI, because of which is the
> First Implementing class. I fixed this issue by setting the following parameter
> in the karaf.sh/bat.
>
> -Djava.naming.factory.initial=com.sun.jndi.rmi.registry.RegistryContextFactory
>
> This way I made sure that the default ContextFactory of the jdk is used (and not the one
> Provided by tomcat at that time)
>
> Greetings, Achim
>
>
> -----Ursprüngliche Nachricht-----
> Von: ext2 [mailto:xuhb@tongtech.com]
> Gesendet: Freitag, 5. November 2010 14:13
> An: user@karaf.apache.org
> Betreff: Re: How about to to facilitate to use JNDI(boot delegation) in karaf?
>
> 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 [gnodet@gmail.com] wrote:
>
>>On Fri, Nov 5, 2010 at 12:02, ext2 <xu...@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 <xu...@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
>
>
>



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

Re: How about to to facilitate to use JNDI(boot delegation) in karaf?

Posted by Mike Van <mv...@comcast.net>.
I'd like to point out that none of the answers, save one, actually addressed
my original question.  Could someone please answer my original question, and
not the one the thread-jacked question?

Mike Van
-- 
View this message in context: http://karaf.922171.n3.nabble.com/Overriding-a-3rd-party-bundle-s-Bunde-ExecutionEnvironment-setting-tp1823817p1862970.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: How about to to facilitate to use JNDI(boot delegation) in karaf?

Posted by ext2 <xu...@tongtech.com>.
I see, thanks a lot;

-----orgin----
Sender: Achim Nierbeck [mailto:Achim.Nierbeck@ptv.de] 
Time: 2010/11/5 23:31
Receiver: user@karaf.apache.org
Subject: AW: How about to to facilitate to use JNDI(boot delegation) in
karaf?

Hi, 

the thing is you do a very tight coupling. Especially when doing "core"
bundles I
would advice not to do it. Just think of this. 

One of you core bundles evolves over time and you want to change just parts
of it
by splitting the bundle in two. 
Now you end up in changing all bundles that require this bundle. The other
way round
if you just depend on packages you might not need to change anything on the 
requiring bundles because the packages are still provided, but now by two
separate bundles.
You should also consider a separation between API and implementation this is
one 
of the major benefits of OSGi and you should consider depending just on api
packages. 

There is quite a good presentation by Martin Lippert on what not to do :)
see [1]

Cheers Achim 

[1] - http://www.martinlippert.com/events/JFS2010-OSGiLessonsLearned.pdf


-----Ursprüngliche Nachricht-----
Von: ext2 [mailto:xuhb@tongtech.com] 
Gesendet: Freitag, 5. November 2010 16:23
An: user@karaf.apache.org
Betreff: Re: How about to to facilitate to use JNDI(boot delegation) in
karaf?


Thanks Achim Nierbeck .
	I am not very clear why the Require-Bundle is not perfered. 
	Do you mean Require-Bundle will cause the bundle who import package
will tightly coupling with the bundle who contribute package?  Or some other
critical reasons which forbidden us to do so?

	I recently have done another work, which does use the
require-bundle. If there is some critical reason caused the Require-Bundle
to be bad, I think I must change my implementation and not to use it.

	Following the summary description of my work:
 I have done several bundles which provide some core business logic, here we
call these bundles as core bundles.  The end user could use a xml to
configure a real application using the core-bundles provided function; Also
each  configured application will be deployed as a bundle; 
	In my solution, the application bundle does use require-bundle to
declare dependency to core-bundles, because the import-package is hard to
analyze and list them all in application bundle;
	If there is some other critical reason which forbidden me to do
so,.......it will be a truly bad news to me;
	

-----origin -----
Sender: Achim Nierbeck [mailto:Achim.Nierbeck@ptv.de] 
Time: 2010/11/5 21:25
Receiver: user@karaf.apache.org
Subject: AW: How about to to facilitate to use JNDI(boot delegation) in
karaf?

Sorry, to interrupt, but Require-Bundle is really bad practice :(


Just one side node from me, I once had also an issue with JNDI, because of
which is the
First Implementing class. I fixed this issue by setting the following
parameter 
in the karaf.sh/bat.

-Djava.naming.factory.initial=com.sun.jndi.rmi.registry.RegistryContextFacto
ry

This way I made sure that the default ContextFactory of the jdk is used (and
not the one
Provided by tomcat at that time)

Greetings, Achim 


-----Ursprüngliche Nachricht-----
Von: ext2 [mailto:xuhb@tongtech.com] 
Gesendet: Freitag, 5. November 2010 14:13
An: user@karaf.apache.org
Betreff: Re: How about to to facilitate to use JNDI(boot delegation) in
karaf?

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 [gnodet@gmail.com] wrote:

>On Fri, Nov 5, 2010 at 12:02, ext2 <xu...@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 <xu...@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







AW: How about to to facilitate to use JNDI(boot delegation) in karaf?

Posted by Achim Nierbeck <Ac...@ptv.de>.
Hi, 

the thing is you do a very tight coupling. Especially when doing "core" bundles I
would advice not to do it. Just think of this. 

One of you core bundles evolves over time and you want to change just parts of it
by splitting the bundle in two. 
Now you end up in changing all bundles that require this bundle. The other way round
if you just depend on packages you might not need to change anything on the 
requiring bundles because the packages are still provided, but now by two
separate bundles.
You should also consider a separation between API and implementation this is one 
of the major benefits of OSGi and you should consider depending just on api packages. 

There is quite a good presentation by Martin Lippert on what not to do :) see [1]

Cheers Achim 

[1] - http://www.martinlippert.com/events/JFS2010-OSGiLessonsLearned.pdf


-----Ursprüngliche Nachricht-----
Von: ext2 [mailto:xuhb@tongtech.com] 
Gesendet: Freitag, 5. November 2010 16:23
An: user@karaf.apache.org
Betreff: Re: How about to to facilitate to use JNDI(boot delegation) in karaf?


Thanks Achim Nierbeck .
	I am not very clear why the Require-Bundle is not perfered. 
	Do you mean Require-Bundle will cause the bundle who import package
will tightly coupling with the bundle who contribute package?  Or some other
critical reasons which forbidden us to do so?

	I recently have done another work, which does use the
require-bundle. If there is some critical reason caused the Require-Bundle
to be bad, I think I must change my implementation and not to use it.

	Following the summary description of my work:
 I have done several bundles which provide some core business logic, here we
call these bundles as core bundles.  The end user could use a xml to
configure a real application using the core-bundles provided function; Also
each  configured application will be deployed as a bundle; 
	In my solution, the application bundle does use require-bundle to
declare dependency to core-bundles, because the import-package is hard to
analyze and list them all in application bundle;
	If there is some other critical reason which forbidden me to do
so,.......it will be a truly bad news to me;
	

-----origin -----
Sender: Achim Nierbeck [mailto:Achim.Nierbeck@ptv.de] 
Time: 2010/11/5 21:25
Receiver: user@karaf.apache.org
Subject: AW: How about to to facilitate to use JNDI(boot delegation) in
karaf?

Sorry, to interrupt, but Require-Bundle is really bad practice :(


Just one side node from me, I once had also an issue with JNDI, because of
which is the
First Implementing class. I fixed this issue by setting the following
parameter 
in the karaf.sh/bat.

-Djava.naming.factory.initial=com.sun.jndi.rmi.registry.RegistryContextFacto
ry

This way I made sure that the default ContextFactory of the jdk is used (and
not the one
Provided by tomcat at that time)

Greetings, Achim 


-----Ursprüngliche Nachricht-----
Von: ext2 [mailto:xuhb@tongtech.com] 
Gesendet: Freitag, 5. November 2010 14:13
An: user@karaf.apache.org
Betreff: Re: How about to to facilitate to use JNDI(boot delegation) in
karaf?

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 [gnodet@gmail.com] wrote:

>On Fri, Nov 5, 2010 at 12:02, ext2 <xu...@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 <xu...@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





Re: How about to to facilitate to use JNDI(boot delegation) in karaf?

Posted by ext2 <xu...@tongtech.com>.
Thanks Achim Nierbeck .
	I am not very clear why the Require-Bundle is not perfered. 
	Do you mean Require-Bundle will cause the bundle who import package
will tightly coupling with the bundle who contribute package?  Or some other
critical reasons which forbidden us to do so?

	I recently have done another work, which does use the
require-bundle. If there is some critical reason caused the Require-Bundle
to be bad, I think I must change my implementation and not to use it.

	Following the summary description of my work:
 I have done several bundles which provide some core business logic, here we
call these bundles as core bundles.  The end user could use a xml to
configure a real application using the core-bundles provided function; Also
each  configured application will be deployed as a bundle; 
	In my solution, the application bundle does use require-bundle to
declare dependency to core-bundles, because the import-package is hard to
analyze and list them all in application bundle;
	If there is some other critical reason which forbidden me to do
so,.......it will be a truly bad news to me;
	

-----origin -----
Sender: Achim Nierbeck [mailto:Achim.Nierbeck@ptv.de] 
Time: 2010/11/5 21:25
Receiver: user@karaf.apache.org
Subject: AW: How about to to facilitate to use JNDI(boot delegation) in
karaf?

Sorry, to interrupt, but Require-Bundle is really bad practice :(


Just one side node from me, I once had also an issue with JNDI, because of
which is the
First Implementing class. I fixed this issue by setting the following
parameter 
in the karaf.sh/bat.

-Djava.naming.factory.initial=com.sun.jndi.rmi.registry.RegistryContextFacto
ry

This way I made sure that the default ContextFactory of the jdk is used (and
not the one
Provided by tomcat at that time)

Greetings, Achim 


-----Ursprüngliche Nachricht-----
Von: ext2 [mailto:xuhb@tongtech.com] 
Gesendet: Freitag, 5. November 2010 14:13
An: user@karaf.apache.org
Betreff: Re: How about to to facilitate to use JNDI(boot delegation) in
karaf?

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 [gnodet@gmail.com] wrote:

>On Fri, Nov 5, 2010 at 12:02, ext2 <xu...@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 <xu...@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





AW: How about to to facilitate to use JNDI(boot delegation) in karaf?

Posted by Achim Nierbeck <Ac...@ptv.de>.
Sorry, to interrupt, but Require-Bundle is really bad practice :(


Just one side node from me, I once had also an issue with JNDI, because of which is the
First Implementing class. I fixed this issue by setting the following parameter 
in the karaf.sh/bat.

-Djava.naming.factory.initial=com.sun.jndi.rmi.registry.RegistryContextFactory

This way I made sure that the default ContextFactory of the jdk is used (and not the one
Provided by tomcat at that time)

Greetings, Achim 


-----Ursprüngliche Nachricht-----
Von: ext2 [mailto:xuhb@tongtech.com] 
Gesendet: Freitag, 5. November 2010 14:13
An: user@karaf.apache.org
Betreff: Re: How about to to facilitate to use JNDI(boot delegation) in karaf?

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 [gnodet@gmail.com] wrote:

>On Fri, Nov 5, 2010 at 12:02, ext2 <xu...@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 <xu...@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



Re: How about to to facilitate to use JNDI(boot delegation) in karaf?

Posted by ext2 <xu...@tongtech.com>.
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 [gnodet@gmail.com] wrote:

>On Fri, Nov 5, 2010 at 12:02, ext2 <xu...@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 <xu...@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



Re: How about to to facilitate to use JNDI(boot delegation) in karaf?

Posted by Guillaume Nodet <gn...@gmail.com>.
On Fri, Nov 5, 2010 at 12:02, ext2 <xu...@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,sun.*,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 <xu...@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

Re: How about to to facilitate to use JNDI(boot delegation) in karaf?

Posted by ext2 <xu...@tongtech.com>.
>: 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;

>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.

On Fri, Nov 5, 2010 at 10:35, ext2 <xu...@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