First, what is OSGi
The OSGi (Open Service Gateway Initiative) technology is a series of specifications for the dynamic modular system of Java. OSGi, on the one hand, refers to the official OSGi alliance that maintains the OSGi specification and, on the other hand, the Java-language-based Service (business) specification maintained by the organization. In simple terms, OSGi can be thought of as the module layer of the Java platform.
The OSGi service platform provides services to Java, which makes Java a preferred environment for software integration and software development. Java provides portability for products that are supported on multiple platforms. OSGi technology provides standardized primitives that allow applications to be built using refined, reusable, and collaborative components that can be assembled into an application and deployment.
Above is just simple from Baidu C some introduction, just need to know is a new framework on it, more than the previous framework used (personally think). And at present a lot of large companies are in use, small use of less, after all, the cost of this high, entry threshold a little bit of that, the first a little confused force.
II. Preparation before development
Development tools: Eclipse + development environment (not to mention the development of it) + Felix (I use 5.4.0)
Development thinking: OSGi is a more nuanced separation of the traditional modules
Felix: The container currently used to run the OSGi project (hot-swappable, Cool ~ ~ ~)
MAVEN Project: Use MAVEN projects, and know what's going on.
Iii. structuring a project for an OSGI framework
3.1 Start Felix first
CMD >> enter Felix's file >>java-jar Bin/felix.jar Okay, now that Felix has been successfully launched, the first step is done.
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M00/84/08/wKioL1eET1zie-dqAAAbpJYKcTQ062.png-wh_500x0-wm_3 -wmp_4-s_2328106332.png "title=" launches Felix "alt=" Wkiol1eet1zie-dqaaabpjykctq062.png-wh_50 "/>
3.2 New Project
Create a new Maven Project >> Choose the QuickStart way to do it, named: email-parnent
Click on the newly created MAVEN project to create a new 4 maven Module (one built) with the name: Email-api, Email-client, email139, email163
Here, 1 MAVEN projects have been built, 4ge module, and these 4 module are Email-parnent's sub-projects.
Go on, if it's already done.
Configuring the Pom file for the Email-parnent project
A, add the following configuration to the <Properties> tag (execute our JDK version)
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
B. Join a dependency
<dependency><groupId>org.osgi</groupId><artifactId>org.osgi.core</artifactId>
<version>6.0.0</version></dependency>
C, continue to configure
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/84/09/wKioL1eEUYzR3n4dAABvK7qJmz4958.png-wh_500x0-wm_3 -wmp_4-s_2514712157.png "title=" parnent configuration. png "alt=" wkiol1eeuyzr3n4daabvk7qjmz4958.png-wh_50 "/>
3.3 Email-api (Put the interface)
Built a package path: ORG.EMAIL.API
Build an interface: Iemailservice
public void SendEmail (String dest,string title,string content);
Next, continue to configure this project:
Note that the following text is used in all implementation projects and in the client;
<groupId>FirstOsgi</groupId>
<artifactId>email-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M00/84/09/wKiom1eEUp2QwME3AAB75pRWGcg510.png-wh_500x0-wm_3 -wmp_4-s_1686867770.png "title=" Api.png "alt=" Wkiom1eeup2qwme3aab75prwgcg510.png-wh_50 "/>
Okay, our API's done.
3.4 email-139 (email163 Same, email-client configuration, coding principle)
It's mapped directly below.
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/84/0A/wKiom1eEVljiZdcmAADDPvB90ZA221.png-wh_500x0-wm_3 -wmp_4-s_418292009.png "title=" Email139.png "alt=" Wkiom1eevljizdcmaaddpvb90za221.png-wh_50 "/>
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/84/0A/wKiom1eEVrmiY2MhAAHP66SXXxE212.jpg-wh_500x0-wm_3 -wmp_4-s_3189789426.jpg "title=" 139impl.jpg "alt=" Wkiom1eevrmiy2mhaahp66sxxxe212.jpg-wh_50 "/>
Four, packaging run it
Directly compile the parent project, Email-parnent, generated 4 jar packages, copy the 4 jar packages to the Felix directory/bundle, OK, the code, the package is ready to complete, directly below the command line deployment.
Enter lb: View the currently running package and ID
Stop 0: Stop the root directory (Felix Container stopped)
Reboot: Java-jar Bin/felix.jar, the jar package under the bundle directory will be compiled automatically, so our OSGi project is OK.
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M00/84/09/wKioL1eEWK7Au6b6AACEOULM65g112.png-wh_500x0-wm_3 -wmp_4-s_1544350181.png "title=" Cmd.png "alt=" Wkiol1eewk7au6b6aaceoulm65g112.png-wh_50 "/>
Summary: The first time to write a blog, write not very detailed, will be more and more good.
This article is from the "5549595" blog, please be sure to keep this source http://5559595.blog.51cto.com/5549595/1825644
The "OSGi QuickStart" understands this at least 2 weeks of reading time