Differences between osgi and normal Java projects in classloader

Source: Internet
Author: User

Under the osgi framework

This. getclass (). getclassloader () = org. Eclipse. osgi. Internal. baseadaptor. defaultclassloader @ 186c6b2

Thread. currentthread (). getcontextclassloader () = org. Eclipse. Core. runtime. Internal. adaptor. contextfinder @ 16b13c7

Classloader. getsystemclassloader () = sun. Misc. launcher $ appclassloader @ 19821f

In common Java programs
This. getclass (). getclassloader () = sun. Misc. launcher $ appclassloader @ 19821f

Thread. currentthread (). getcontextclassloader () = sun. Misc. launcher $ appclassloader @ 19821f

Classloader. getsystemclassloader () = sun. Misc. launcher $ appclassloader @ 19821f

From this we can see that under the osgi framework, if classes that are not in the bin directory of this bundle are dynamically loaded, only classloader. getsystemclassloader () is used ().

In addition, it is found that in the osgi framework, the other two class loaders are used to load non-bin directories (the default class output path of this bundle), even if the absolute path is given, the system will also encounter an exception where the class cannot be found.

Note that this. getclass (). getclassloader () and thread. currentthread (). getcontextclassloader () can be assigned to a urlclassloader just like a normal Java project, but an exception that cannot be forcibly converted will occur during running. This analysis shows that this. getclass (). getclassloader () and thread. currentthread (). getcontextclassloader () in the osgi framework are different from those in Java. Pay more attention when using it in the future.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.