Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [equinox-dev] java.lang.NoClassDefFoundError: sun/reflect/ReflectionFactory

2008/7/7 Nikhil Sharma <niksharma@xxxxxxxxx>:
Hi,
When i try to use -

final

ReflectionFactory reflectionFactory = ReflectionFactory.getReflectionFactory();

in a bundle it throws a -

java.lang.NoClassDefFoundError: sun/reflect/ReflectionFactory

What might be the reason for this.

do you import the "sun.reflect" package in your bundle manifest?

this is a simplification, but basically the packages that a bundle can see are:

   1)  those listed under the "org.osgi.framework.bootdelegation" property AND available from the framework's bootclasspath

   2)  those contained inside the bundle

   3)  those imported via Import-Package (or DynamicImport-Package) AND exported from another bundle with matching constraints (versions, attributes, etc.)

   4)  those visible from another bundle via Require-Bundle

but I strongly recommend you read the OSGi spec as it has a much clearer
(and definitive) description of package visibility in OSGi, along with pictures!

typically the "org.osgi.framework.bootdelegation" property defaults to "java.*"
so if you don't import the "sun.reflect" package, or no other bundle exports it,
then you will see a NCDF error.

if the system bundle (usually bundle 0) exports "sun.reflect" then you just need
to add this package to your Import-Package in the manifest - otherwise you can
try adding it to the bootdelegation list, though this is less flexible because your
bundle then depends on this property being set correctly

as a side note, it is bad practice to depend on "sun.*" packages as these are
private Sun implementation classes, and are not part of the public Java API.

these classes may change or disappear between Java releases depending on
how Sun feels - and may not be available on non-Sun implementations of Java.

HTH

_______________________________________________
equinox-dev mailing list
equinox-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/equinox-dev




--
Cheers, Stuart

Back to the top