Code explanation for implementing the Class Loader Mechanism Using equinox (3)

Source: Internet
Author: User

In the development process of the team, it is inevitable that a package is declared inside the bundle, and the same package is imported from the external, what will happen?

To make a small experiment.

1. Create two plug-in projects.

A. Create the first plug-in Project

B. Create a second plug-in project.

2. In addition to different packages, each project also declares the same package name.
Create a class with the same name in the same package name, as shown in.

3. write code

A. The first sameclass. Java code

Package org. teamlet. samepackage;

Public class sameclass {
Public void toshow (){
System. Out. println ("*** I am inside! ");
}
}

B. The second sameclass. Java code

Package org. teamlet. samepackage;

Public class sameclass {
Public void toshow (){
System. Out. println ("*** I am outside! ");
}
}

 

4. Export the import package

Add and export to the manifest. MF file of Equinox. EVN. Test. samepackage (containing "I am outside" content) in the first project:

Export-package: org. teamlet. samepackage

Add import to the manifest. MF file of org. teamlet. osgi. Test (containing "I am inside") in the second project:

Import-package: org. osgi. Framework; version = "1.3.0 ",
Org. teamlet. samepackage

5. Add a call

The START () method in the activator of org. teamlet. osgi. Test in the second project calls sameclass.

Public void start (bundlecontext context) throws exception {
Sameclass SC = new sameclass ();
SC. toshow ();
}

6. Execute

7. Conclusion

If a bundle introduces the same package as an internal package, it uses the imported package instead of the internal package.

The sequence of class searching in equinox's code interpretation of implementing the Class Loader mechanism (1) is clear.

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.