Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » ClassNotFoundException with classes inside jre/lib/ext
ClassNotFoundException with classes inside jre/lib/ext [message #34316] Tue, 25 November 2008 12:15 Go to next message
Eclipse User
Originally posted by: massimiliano.ziccardi.gmail.com

Hi All.

I'm quite new to eclipse plugins.

I wrote a plugin and had no problem.
Now I need to use some BouncyCastle classes, so I added the
bouncycastle jars inside the jre/lib/ext directory and configured the
provider inside the java.security file.

In my RCP.product file, I configured the JRE Name (Launching TAB) so
that my JRE with Bouncycastle will be embedded inside my product.

I've exported the application and verified that the jre/lib/ext is ok:
it's ok.

However, when I execute some of my plugin functions, I get this:

java.lang.NoClassDefFoundError:
org/bouncycastle/jce/provider/BouncyCastleProvider
at
it.intesa.tstation.plugins.etsi.keystore.pkcs12.preferences. P12ConfigDialogContent$2.widgetSelected(P12ConfigDialogConte nt.java:101)
at
org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListe ner.java:228)
at
org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1158)
.....

and, the important part (I think):

Caused by: java.lang.ClassNotFoundException:
org.bouncycastle.jce.provider.BouncyCastleProvider
at
org.eclipse.osgi.framework.internal.core.BundleLoader.findCl assInternal(BundleLoader.java:481)
at
org.eclipse.osgi.framework.internal.core.BundleLoader.findCl ass(BundleLoader.java:397)
at
org.eclipse.osgi.framework.internal.core.BundleLoader.findCl ass(BundleLoader.java:385)
at
org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loa dClass(DefaultClassLoader.java:87)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at
java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319 )


Do you have any idea about what I miss?

Thanks in advance,
Massimiliano Ziccardi
Re: ClassNotFoundException with classes inside jre/lib/ext [message #34386 is a reply to message #34316] Tue, 25 November 2008 15:29 Go to previous messageGo to next message
Eclipse User
Originally posted by: ziccardi.email.it

Hi all. I made one step forward.

I tried to instantiate the BouncyCastleProvider directly inside my
plugin (i.e. new BouncyCastleProvider()).

Now I get a compile error saying:
"
The constructor BouncyCastleProvider() is not accessible due to
restriction to the require library...
"

How can I change this restrictions?

Many thanks,
Massimiliano
Re: ClassNotFoundException with classes inside jre/lib/ext [message #34420 is a reply to message #34386] Tue, 25 November 2008 15:54 Go to previous messageGo to next message
Stefan   is currently offline Stefan
Messages: 316
Registered: July 2009
Senior Member
Hi,

did you specify the package of BouncyCastleProvider as Export-Packages /
Import-Packages in your Manifests?

Regards,
Stefan.

ziccardi schrieb:
>
> Hi all. I made one step forward.
>
> I tried to instantiate the BouncyCastleProvider directly inside my
> plugin (i.e. new BouncyCastleProvider()).
>
> Now I get a compile error saying:
> "
> The constructor BouncyCastleProvider() is not accessible due to
> restriction to the require library...
> "
>
> How can I change this restrictions?
>
> Many thanks,
> Massimiliano
Re: ClassNotFoundException with classes inside jre/lib/ext [message #34454 is a reply to message #34420] Tue, 25 November 2008 16:11 Go to previous messageGo to next message
Eclipse User
Originally posted by: massimiliano.ziccardi.gmail.com

Hi Stephan!

Thank you very much for your help.

I tried to export the packages as you told, but I cannot see them (when
I click on Add, the bouncycastle packages are not shown).

I even tried to add the bouncycastle's library inside the plugin, than
I've been able to export the packages.

This way it worked, except the fact that the library has been loaded by
two different classloaders (infact it is inside the jre/lib/ext and
inside the plugin): this way I got :
cannot cast class PBEKey to class PBEKey (an obvious classloader issue).

What do I still make wrong?

Thank you!,
Massimiliano
Re: ClassNotFoundException with classes inside jre/lib/ext [message #34488 is a reply to message #34454] Tue, 25 November 2008 17:16 Go to previous messageGo to next message
Stefan   is currently offline Stefan
Messages: 316
Registered: July 2009
Senior Member
Hi,

the setting should look like this:

Bundle A (containing BouncyCastleProvider)
Export-Package: org.bouncycastle.jce.provider

Bundle B (referencing BouncyCastleProvider)
Import-Package: org.bouncycastle.jce.provider

Maybe, there are additional packages which are indirectly referenced by
BouncyCastleProvider which you have to add to both lists.

Now, you should have no classloader issues any more.

Regards, Stefan.

ziccardi schrieb:
> Hi Stephan!
>
> Thank you very much for your help.
>
> I tried to export the packages as you told, but I cannot see them (when
> I click on Add, the bouncycastle packages are not shown).
>
> I even tried to add the bouncycastle's library inside the plugin, than
> I've been able to export the packages.
>
> This way it worked, except the fact that the library has been loaded by
> two different classloaders (infact it is inside the jre/lib/ext and
> inside the plugin): this way I got :
> cannot cast class PBEKey to class PBEKey (an obvious classloader issue).
>
> What do I still make wrong?
>
> Thank you!,
> Massimiliano
Re: ClassNotFoundException with classes inside jre/lib/ext [message #34625 is a reply to message #34488] Wed, 26 November 2008 11:03 Go to previous messageGo to next message
Eclipse User
Originally posted by: massimiliano.ziccardi.gmail.com

Not sure I did it the right way.
At the moment it works, but I'm not sure my solution won't create other
problems.

The problem was the following.

The bouncycastle security provider was configured inside the
java.security file (and was placed inside jre/lib/ext directory).

The problem was about a call inside the code, where I used some security
class passing as provider 'new BouncyCastleProvider()'.

The exact code was (one of the many):

KeyStore ks = KeyStore.getInstance("PKCS12",new BouncyCastleProvider());

I solved it changing the code to:

KeyStore ks = KeyStore.getInstance("PKCS12",Security.getProvider("BC"));

Than, I created a plugin containing only the bouncycastle classes.
This plugin exports bouncycastle packages.

The other plugins that needs bouncycastle's api, simply depends on the
bouncycastle plugin.

However, I'm not sure I wont' meet the problem again with other
bouncycastle's apis...

Do you think I did right?

Thank you very much for your help!

Regards,
Massimiliano Ziccardi

Stefan Roeck wrote:
> Hi,
>
> the setting should look like this:
>
> Bundle A (containing BouncyCastleProvider)
> Export-Package: org.bouncycastle.jce.provider
>
> Bundle B (referencing BouncyCastleProvider)
> Import-Package: org.bouncycastle.jce.provider
>
> Maybe, there are additional packages which are indirectly referenced by
> BouncyCastleProvider which you have to add to both lists.
>
> Now, you should have no classloader issues any more.
>
> Regards, Stefan.
>
> ziccardi schrieb:
>> Hi Stephan!
>>
>> Thank you very much for your help.
>>
>> I tried to export the packages as you told, but I cannot see them
>> (when I click on Add, the bouncycastle packages are not shown).
>>
>> I even tried to add the bouncycastle's library inside the plugin, than
>> I've been able to export the packages.
>>
>> This way it worked, except the fact that the library has been loaded
>> by two different classloaders (infact it is inside the jre/lib/ext and
>> inside the plugin): this way I got :
>> cannot cast class PBEKey to class PBEKey (an obvious classloader issue).
>>
>> What do I still make wrong?
>>
>> Thank you!,
>> Massimiliano
Re: ClassNotFoundException with classes inside jre/lib/ext [message #34693 is a reply to message #34625] Wed, 26 November 2008 16:22 Go to previous messageGo to next message
Andrew Niefer is currently offline Andrew Niefer
Messages: 990
Registered: July 2009
Senior Member
Massimiliano,
Putting the Bouncy Castle classes in their own plugin is the best solution.

I think the problems you had before when they were in jre/lib/ext are to
do with boot delegation [1] and execution environments [2].
The short explanation being that by default you can only see the
packages from the vm that are exported by the system bundle
(org.eclipse.osgi). This list of packages is determined by an execution
environment profile, which of course does not include the Bouncy Castle
packages.

To use Bouncy Castle packages from the jre/lib/ext directory, you would
either need to change org.osgi.framework.bootdelegation, or use a custom
execution environment (I'm not sure of the details for that).

[1] http://wiki.eclipse.org/Equinox_Boot_Delegation
[2] http://wiki.eclipse.org/Execution_Environment

-Andrew
Massimiliano Ziccardi wrote:
> Not sure I did it the right way.
> At the moment it works, but I'm not sure my solution won't create other
> problems.
>
> The problem was the following.
>
> The bouncycastle security provider was configured inside the
> java.security file (and was placed inside jre/lib/ext directory).
>
> The problem was about a call inside the code, where I used some security
> class passing as provider 'new BouncyCastleProvider()'.
>
> The exact code was (one of the many):
>
> KeyStore ks = KeyStore.getInstance("PKCS12",new BouncyCastleProvider());
>
> I solved it changing the code to:
>
> KeyStore ks = KeyStore.getInstance("PKCS12",Security.getProvider("BC"));
>
> Than, I created a plugin containing only the bouncycastle classes.
> This plugin exports bouncycastle packages.
>
> The other plugins that needs bouncycastle's api, simply depends on the
> bouncycastle plugin.
>
> However, I'm not sure I wont' meet the problem again with other
> bouncycastle's apis...
>
> Do you think I did right?
>
> Thank you very much for your help!
>
> Regards,
> Massimiliano Ziccardi
>
> Stefan Roeck wrote:
>> Hi,
>>
>> the setting should look like this:
>>
>> Bundle A (containing BouncyCastleProvider)
>> Export-Package: org.bouncycastle.jce.provider
>>
>> Bundle B (referencing BouncyCastleProvider)
>> Import-Package: org.bouncycastle.jce.provider
>>
>> Maybe, there are additional packages which are indirectly referenced
>> by BouncyCastleProvider which you have to add to both lists.
>>
>> Now, you should have no classloader issues any more.
>>
>> Regards, Stefan.
>>
>> ziccardi schrieb:
>>> Hi Stephan!
>>>
>>> Thank you very much for your help.
>>>
>>> I tried to export the packages as you told, but I cannot see them
>>> (when I click on Add, the bouncycastle packages are not shown).
>>>
>>> I even tried to add the bouncycastle's library inside the plugin, than
>>> I've been able to export the packages.
>>>
>>> This way it worked, except the fact that the library has been loaded
>>> by two different classloaders (infact it is inside the jre/lib/ext
>>> and inside the plugin): this way I got :
>>> cannot cast class PBEKey to class PBEKey (an obvious classloader issue).
>>>
>>> What do I still make wrong?
>>>
>>> Thank you!,
>>> Massimiliano
Re: ClassNotFoundException with classes inside jre/lib/ext [message #34797 is a reply to message #34693] Thu, 27 November 2008 09:19 Go to previous messageGo to next message
Eclipse User
Originally posted by: massimiliano.ziccardi.gmail.com

Hi Andrew.

I read the documentation at the links you provider.
That was exactly what I needed!

Thank you very much!

One last question: to change the org.osgi.framework.bootdelegation do I
have to change some configuration file? Or the only way is to put an
-Dorg.osgi.framework.bootdelegation=org.bouncycastle.* as VM parameter?
(sorry for the newbie question: this is my first RCP application)

Thank you again,
Massimiliano Ziccardi
Re: ClassNotFoundException with classes inside jre/lib/ext [message #34993 is a reply to message #34797] Thu, 27 November 2008 22:41 Go to previous message
Andrew Niefer is currently offline Andrew Niefer
Messages: 990
Registered: July 2009
Senior Member
You can set this in the configuration/config.ini file.
I think that setting it as a vm property will work as well.

-Andrew

Massimiliano Ziccardi wrote:
> Hi Andrew.
>
> I read the documentation at the links you provider.
> That was exactly what I needed!
>
> Thank you very much!
>
> One last question: to change the org.osgi.framework.bootdelegation do I
> have to change some configuration file? Or the only way is to put an
> -Dorg.osgi.framework.bootdelegation=org.bouncycastle.* as VM parameter?
> (sorry for the newbie question: this is my first RCP application)
>
> Thank you again,
> Massimiliano Ziccardi
Re: ClassNotFoundException with classes inside jre/lib/ext [message #585802 is a reply to message #34316] Tue, 25 November 2008 15:29 Go to previous message
Eclipse User
Originally posted by: ziccardi.email.it

Hi all. I made one step forward.

I tried to instantiate the BouncyCastleProvider directly inside my
plugin (i.e. new BouncyCastleProvider()).

Now I get a compile error saying:
"
The constructor BouncyCastleProvider() is not accessible due to
restriction to the require library...
"

How can I change this restrictions?

Many thanks,
Massimiliano
Re: ClassNotFoundException with classes inside jre/lib/ext [message #585812 is a reply to message #34386] Tue, 25 November 2008 15:54 Go to previous message
Stefan   is currently offline Stefan
Messages: 316
Registered: July 2009
Senior Member
Hi,

did you specify the package of BouncyCastleProvider as Export-Packages /
Import-Packages in your Manifests?

Regards,
Stefan.

ziccardi schrieb:
>
> Hi all. I made one step forward.
>
> I tried to instantiate the BouncyCastleProvider directly inside my
> plugin (i.e. new BouncyCastleProvider()).
>
> Now I get a compile error saying:
> "
> The constructor BouncyCastleProvider() is not accessible due to
> restriction to the require library...
> "
>
> How can I change this restrictions?
>
> Many thanks,
> Massimiliano
Re: ClassNotFoundException with classes inside jre/lib/ext [message #585824 is a reply to message #34420] Tue, 25 November 2008 16:11 Go to previous message
Eclipse User
Originally posted by: massimiliano.ziccardi.gmail.com

Hi Stephan!

Thank you very much for your help.

I tried to export the packages as you told, but I cannot see them (when
I click on Add, the bouncycastle packages are not shown).

I even tried to add the bouncycastle's library inside the plugin, than
I've been able to export the packages.

This way it worked, except the fact that the library has been loaded by
two different classloaders (infact it is inside the jre/lib/ext and
inside the plugin): this way I got :
cannot cast class PBEKey to class PBEKey (an obvious classloader issue).

What do I still make wrong?

Thank you!,
Massimiliano
Re: ClassNotFoundException with classes inside jre/lib/ext [message #585833 is a reply to message #34454] Tue, 25 November 2008 17:16 Go to previous message
Stefan   is currently offline Stefan
Messages: 316
Registered: July 2009
Senior Member
Hi,

the setting should look like this:

Bundle A (containing BouncyCastleProvider)
Export-Package: org.bouncycastle.jce.provider

Bundle B (referencing BouncyCastleProvider)
Import-Package: org.bouncycastle.jce.provider

Maybe, there are additional packages which are indirectly referenced by
BouncyCastleProvider which you have to add to both lists.

Now, you should have no classloader issues any more.

Regards, Stefan.

ziccardi schrieb:
> Hi Stephan!
>
> Thank you very much for your help.
>
> I tried to export the packages as you told, but I cannot see them (when
> I click on Add, the bouncycastle packages are not shown).
>
> I even tried to add the bouncycastle's library inside the plugin, than
> I've been able to export the packages.
>
> This way it worked, except the fact that the library has been loaded by
> two different classloaders (infact it is inside the jre/lib/ext and
> inside the plugin): this way I got :
> cannot cast class PBEKey to class PBEKey (an obvious classloader issue).
>
> What do I still make wrong?
>
> Thank you!,
> Massimiliano
Re: ClassNotFoundException with classes inside jre/lib/ext [message #585891 is a reply to message #34488] Wed, 26 November 2008 11:03 Go to previous message
Massimiliano Ziccardi is currently offline Massimiliano Ziccardi
Messages: 12
Registered: July 2009
Junior Member
Not sure I did it the right way.
At the moment it works, but I'm not sure my solution won't create other
problems.

The problem was the following.

The bouncycastle security provider was configured inside the
java.security file (and was placed inside jre/lib/ext directory).

The problem was about a call inside the code, where I used some security
class passing as provider 'new BouncyCastleProvider()'.

The exact code was (one of the many):

KeyStore ks = KeyStore.getInstance("PKCS12",new BouncyCastleProvider());

I solved it changing the code to:

KeyStore ks = KeyStore.getInstance("PKCS12",Security.getProvider("BC"));

Than, I created a plugin containing only the bouncycastle classes.
This plugin exports bouncycastle packages.

The other plugins that needs bouncycastle's api, simply depends on the
bouncycastle plugin.

However, I'm not sure I wont' meet the problem again with other
bouncycastle's apis...

Do you think I did right?

Thank you very much for your help!

Regards,
Massimiliano Ziccardi

Stefan Roeck wrote:
> Hi,
>
> the setting should look like this:
>
> Bundle A (containing BouncyCastleProvider)
> Export-Package: org.bouncycastle.jce.provider
>
> Bundle B (referencing BouncyCastleProvider)
> Import-Package: org.bouncycastle.jce.provider
>
> Maybe, there are additional packages which are indirectly referenced by
> BouncyCastleProvider which you have to add to both lists.
>
> Now, you should have no classloader issues any more.
>
> Regards, Stefan.
>
> ziccardi schrieb:
>> Hi Stephan!
>>
>> Thank you very much for your help.
>>
>> I tried to export the packages as you told, but I cannot see them
>> (when I click on Add, the bouncycastle packages are not shown).
>>
>> I even tried to add the bouncycastle's library inside the plugin, than
>> I've been able to export the packages.
>>
>> This way it worked, except the fact that the library has been loaded
>> by two different classloaders (infact it is inside the jre/lib/ext and
>> inside the plugin): this way I got :
>> cannot cast class PBEKey to class PBEKey (an obvious classloader issue).
>>
>> What do I still make wrong?
>>
>> Thank you!,
>> Massimiliano
Re: ClassNotFoundException with classes inside jre/lib/ext [message #585914 is a reply to message #34625] Wed, 26 November 2008 16:22 Go to previous message
Andrew Niefer is currently offline Andrew Niefer
Messages: 990
Registered: July 2009
Senior Member
Massimiliano,
Putting the Bouncy Castle classes in their own plugin is the best solution.

I think the problems you had before when they were in jre/lib/ext are to
do with boot delegation [1] and execution environments [2].
The short explanation being that by default you can only see the
packages from the vm that are exported by the system bundle
(org.eclipse.osgi). This list of packages is determined by an execution
environment profile, which of course does not include the Bouncy Castle
packages.

To use Bouncy Castle packages from the jre/lib/ext directory, you would
either need to change org.osgi.framework.bootdelegation, or use a custom
execution environment (I'm not sure of the details for that).

[1] http://wiki.eclipse.org/Equinox_Boot_Delegation
[2] http://wiki.eclipse.org/Execution_Environment

-Andrew
Massimiliano Ziccardi wrote:
> Not sure I did it the right way.
> At the moment it works, but I'm not sure my solution won't create other
> problems.
>
> The problem was the following.
>
> The bouncycastle security provider was configured inside the
> java.security file (and was placed inside jre/lib/ext directory).
>
> The problem was about a call inside the code, where I used some security
> class passing as provider 'new BouncyCastleProvider()'.
>
> The exact code was (one of the many):
>
> KeyStore ks = KeyStore.getInstance("PKCS12",new BouncyCastleProvider());
>
> I solved it changing the code to:
>
> KeyStore ks = KeyStore.getInstance("PKCS12",Security.getProvider("BC"));
>
> Than, I created a plugin containing only the bouncycastle classes.
> This plugin exports bouncycastle packages.
>
> The other plugins that needs bouncycastle's api, simply depends on the
> bouncycastle plugin.
>
> However, I'm not sure I wont' meet the problem again with other
> bouncycastle's apis...
>
> Do you think I did right?
>
> Thank you very much for your help!
>
> Regards,
> Massimiliano Ziccardi
>
> Stefan Roeck wrote:
>> Hi,
>>
>> the setting should look like this:
>>
>> Bundle A (containing BouncyCastleProvider)
>> Export-Package: org.bouncycastle.jce.provider
>>
>> Bundle B (referencing BouncyCastleProvider)
>> Import-Package: org.bouncycastle.jce.provider
>>
>> Maybe, there are additional packages which are indirectly referenced
>> by BouncyCastleProvider which you have to add to both lists.
>>
>> Now, you should have no classloader issues any more.
>>
>> Regards, Stefan.
>>
>> ziccardi schrieb:
>>> Hi Stephan!
>>>
>>> Thank you very much for your help.
>>>
>>> I tried to export the packages as you told, but I cannot see them
>>> (when I click on Add, the bouncycastle packages are not shown).
>>>
>>> I even tried to add the bouncycastle's library inside the plugin, than
>>> I've been able to export the packages.
>>>
>>> This way it worked, except the fact that the library has been loaded
>>> by two different classloaders (infact it is inside the jre/lib/ext
>>> and inside the plugin): this way I got :
>>> cannot cast class PBEKey to class PBEKey (an obvious classloader issue).
>>>
>>> What do I still make wrong?
>>>
>>> Thank you!,
>>> Massimiliano
Re: ClassNotFoundException with classes inside jre/lib/ext [message #585960 is a reply to message #34693] Thu, 27 November 2008 09:19 Go to previous message
Massimiliano Ziccardi is currently offline Massimiliano Ziccardi
Messages: 12
Registered: July 2009
Junior Member
Hi Andrew.

I read the documentation at the links you provider.
That was exactly what I needed!

Thank you very much!

One last question: to change the org.osgi.framework.bootdelegation do I
have to change some configuration file? Or the only way is to put an
-Dorg.osgi.framework.bootdelegation=org.bouncycastle.* as VM parameter?
(sorry for the newbie question: this is my first RCP application)

Thank you again,
Massimiliano Ziccardi
Re: ClassNotFoundException with classes inside jre/lib/ext [message #586064 is a reply to message #34797] Thu, 27 November 2008 22:41 Go to previous message
Andrew Niefer is currently offline Andrew Niefer
Messages: 990
Registered: July 2009
Senior Member
You can set this in the configuration/config.ini file.
I think that setting it as a vm property will work as well.

-Andrew

Massimiliano Ziccardi wrote:
> Hi Andrew.
>
> I read the documentation at the links you provider.
> That was exactly what I needed!
>
> Thank you very much!
>
> One last question: to change the org.osgi.framework.bootdelegation do I
> have to change some configuration file? Or the only way is to put an
> -Dorg.osgi.framework.bootdelegation=org.bouncycastle.* as VM parameter?
> (sorry for the newbie question: this is my first RCP application)
>
> Thank you again,
> Massimiliano Ziccardi
Previous Topic:Re: 3.5M3 crashes Invalid memory access of location
Next Topic:Presentation based on Model
Goto Forum:
  


Current Time: Tue Oct 21 21:50:18 GMT 2014

Powered by FUDForum. Page generated in 0.02069 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software