Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is OSGI?

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "what is OSGI". In the operation of actual cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

First acquaintance with OSGI background

At present, product is sold in the way of solution, but with the rapid exaggeration of the company's business scale, it is followed by product development of new customers, product maintenance, upgrade and modification of bug for old customers, and the efficiency of the team is significantly degraded. In order to solve such problems, we must stand at the unified height of the company's strategy to reconstruct the system.

It is an honor for me to join the team at this time and be responsible for the upgrade and reconstruction of the system architecture. Because the company has customers all over the world, and the customers come from various industries, the problem is how to pull away from the public business without affecting the customized demand development of customers? The product team focuses on the core logic of the system, while some customized requirements are delivered to global team for development.

Type selection

There is no silver bullet in the technology, so I am not completely sure to use OSGI to implement it, because I used Spring Cloud & Spring Cloud Alibaba to implement a demo. Of course, I can also achieve our service, high availability and dynamic expansion. But when it comes to the customization of plug-ins, it's still relatively unfamiliar, and then OSGI comes into view.

Introduction to OSGI

OSGI is Open Service Gateway Initiative (Development Services Gateway Protocol).

An official alliance that maintains the OSGI specification

> OSGi Alliance is an open standardization organization founded by Sun Microsystems, IBM and Ericsson in March 1999, originally called Connected Alliance.

Service specification based on JAVA language maintained by the official alliance

The specification and core part is a framework that defines the lifecycle pattern and service registration of the application. Based on this framework, a large number of OSGi services are defined: logging, configuration management, preferences, HTTP (running servlet), XML analysis, device access, software package management, license management, star, user management, IO connection management, connection management, Jini and UPnP.

Osgi.org official description:

> The Dynamic Module System for JAVA

Generally speaking: a program implemented using OSGI (Bundle) is a plug-in that can be dynamically installed, uninstalled, started, stopped, etc., without the need to start the container.

The two most widely used OSGI frameworks are:

Apache Felix

> Apache Felix is an OSGi framework under Apache. The project itself is very mature and has been used in many other projects, such as Apache Servicemix. It also provides the most comprehensive service, covering almost all of the OSGi 4.2 standards. In addition, some non-standard features are provided, such as iPOJO. The framework itself is very compact, you only need 3 packages plus a shell to run, both development and Debug are very easy. In addition to Felix, there are two other projects related to OSGi. One is Apache Felix Karaf, which itself is a subproject of Felix, but it actually encapsulates Felix to provide a higher layer of Runtime, such as JAAS. The other is Apache Aries, which is still in its infancy. As a supplement to Felix, it provides OSGi enterprise specifications, including JPA, JDBC, JTA, JNDI, and so on.

Equinox

> Equinox, an OSGi framework under Eclipse, is also adopted by Eclipse and is the underlying layer of the PDE development environment indicated by Eclipse. Equinox itself is a fairly comprehensive framework, providing not much less functionality than Felix. But the classification of its functions is a little confusing, and the documentation and Sample are not well organized. In fact, quite Equinox is still regarded as the development of Eclipse Plugin applications, if you want to develop a Web program, you will feel that its own functions and documentation are not comprehensive enough. The biggest advantage of Equinox is that it is closely integrated with Eclipse, as long as you install PDE, you already have Equinox, you can easily set up your developed Bundle in Eclipse, startup, deployment and other operations are also very simple, and there is a special Debug interface, what else can you ask for? > > if you want to develop based on Eclipse, Equinox is undoubtedly a good choice. But for beginners, they sometimes confuse the relationship between Eclipse Plugin and OSGi.

Talk is cheap, Show me the code. The environment installs the Eclipse version

Since I haven't used Eclipse for several years, I'll take the installation and get familiar with it again.

Access: https://www.eclipse.org/downloads/ download client

After selecting the enterprise version, the next step

Click INSTALL and wait for the installation to complete.

Create a project

File = > New = > Project

Select Plug-in Development = > Plug-in Project

Fill in the project properties (OSGI framework Select standard)

Click Next (follow Activator, which is called when dealing with start () and stop () of OSGI, which is equivalent to our main function)

Click Next (choose Hello OSGI)

Click Finish

Configure the environment

Select Run = > Run Configurations

Select OSGI Framework and right-click New Configration

Select Bundles (because all Target Platform are selected by default, under Eclipse IDE 201919mur09 version, an error will be reported if you start directly. So it's enough to uncheck all the options and just check the necessary bundle below. )

Click Validate Bundles to verify that our configuration item is correct.

If the above message is displayed, congratulations, you can click Run to start OSGI console!

OSGI Console start

IDEA version

IDEA also comes with the OSGI development kit, let's do it.

Configure Framework

Here I choose the Eclipse Equinox 4.13 download portal, click download [equinox-SDK-4.13.zip], and start the configuration after the download is complete.

IDEA (version: ULTIMATE 2019.2) = > File = > Settings (search OSGI, as shown below)

Click + add, and select the SDK directory downloaded in the previous step.

After adding successfully, select the OSGI tag and select the Equinox that OSGI framework configures for us.

> import Bnd/Bndtools projects automatically refers to packaging a normal jar package into a jar available to OSGI.

Create a project

Click File = > New = > Project, and select OSGI under the Java tab

Select Use Library and click Create

Find org.eclipse.osgi_3.15.0.v20190830-1434.jar, select, the effect is as follows, and click next.

Fill in the project properties

Click Finish.

As shown in the figure above, what IDEA created will not help us generate Activator and Manifest.mf files.

OSGI Console start

Click Run = > Edit Configurations

Click +, select OSGI Bundles, and add core bundles

Run (ss to view OSGI running status command)

There is a big difference between Eclipse and IDEA in developing OSGI, mainly in the process of generating manifast files.

That's all for "what OSGI is". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report