OSGi after working on the first project. Even Java is not how can, all of a sudden with OSGi, all kinds of concept nouns do not understand, and there is no time to study deeply, only in the framework has been set up to write transactions, write business processes, database additions and deletions to change, after a long time to understand slowly.
This series of notes mainly introduces the OSGi technology and principles used in our project in an instance, mainly including the service encapsulation and release of OSGi's Helloworld,osgi, the combination of OSGi and spring Springdm,osgi class loading principle , the test of OSGi.
OSGI HelloWorld
(1) Open Eclipse and open a new workspace, create a new plug-in Project
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6E/67/wKioL1V7tAzgFax_AAFkmFYoDck685.jpg "title=" 1.png " alt= "Wkiol1v7tazgfax_aafkmfyodck685.jpg"/>
(2) need to select a framework
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6E/6B/wKiom1V7srSD4uyQAAHjV9uhFmM792.jpg "title=" 2.png " alt= "Wkiom1v7srsd4uyqaahjv9uhfmm792.jpg"/>
(3) Select Generate a Activator
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6E/67/wKioL1V7tOixUkQiAAHWBCzjVzw407.jpg "title=" 4.png " alt= "Wkiol1v7toixukqiaahwbczjvzw407.jpg"/>
(4) No template required, direct finish
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6E/6B/wKiom1V7s3TxBQKhAAF1THj4yg8413.jpg "title=" 5.png " alt= "Wkiom1v7s3txbqkhaaf1thj4yg8413.jpg"/>
(5) An OSGi bundle is built.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6E/67/wKioL1V7tVDAA9cPAAKGtERZgko018.jpg "title=" 6.png " alt= "Wkiol1v7tvdaa9cpaakgterzgko018.jpg"/>
(6) Modify the Activator code
Public classactivator implements bundleactivator { private static BundleContext context; static BundleContext GetContext () { return context; } public void start (BundleContext Bundlecontext) throws exception { Activator.context = bundleContext; system.out.println ("Hello world"); } public void stop (Bundlecontext bundlecontext) throws Exception { Activator.context = Null; system.out.println ("Goodbye world"); } }
(7) Click Run->debug Configuration to create a new OSGi configuration
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6E/67/wKioL1V7um6SRfQJAANIcnsLyWk047.jpg "style=" float: none; "title=" 7.png "alt=" Wkiol1v7um6srfqjaanicnslywk047.jpg "/>
(8) Select the bundle with target platform in the diagram and debug
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6E/6B/wKiom1V7uMXQdIDDAAW7WOx1ifo851.jpg "style=" float: none; "title=" 8.png "alt=" Wkiom1v7umxqdiddaaw7wox1ifo851.jpg "/>
(9) The program, using the SS command to view the bundle status, and then stop our own written bundles, and then start, we see Hello World and Goodbye world.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6E/67/wKioL1V7um6gyHQ3AAGtu2rm6Xg816.jpg "title=" 9.png " alt= "Wkiol1v7um6gyhq3aagtu2rm6xg816.jpg"/>
This article from "Niu Blog" blog, reproduced please contact the author!
OSGi Learning (1)-HelloWorld