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.