Equinox osgi Series II builds equinox osgi Core Environment

Source: Internet
Author: User
Document directory
  • 4.1 original osgi Environment
  • 4.2 deploy bundle to the osgi environment using running parameters
  • 4.3 deploy bundle to the osgi environment as a configuration file
  • 5.1 use the eclipse. ini file
1. Overview

As mentioned above, equinox includes the core framework, standard service implementation, J2EE-oriented applications, new deployment and update frameworks, and some other research directions. This article focuses on the osgi core framework implemented by equinox and the setup process of the Equinox osgi runtime environment.

Users should have basic Java programming and packaging concepts, have a certain understanding of the composition of osgi standards, and understand the osgi framework and bundle concepts.

2. osgi core framework

From the osgi core framework, we can see that the osgi core framework consists of the module layer, lifecycle layer, service layer, and security layer. Complete osgi core framework implementation, including package admin, start level, conditional permission admin, and permission Admin) URL handlers and other framework services.

For details about the osgi core framework, see osgi standard specifications.

3. equinox osgi Framework Implementation

The osgi Framework Implementation of Equinox is included in the org. Eclipse. osgi plug-in project. In the released eclipse environment, you can find the plug-in the Plugins directory under the eclipse installation directory. This plug-in is generally packaged as a jar file of "org. Eclipse. osgi _ <version>. Jar. The Code included in the Equinox osgi implementation is complex because it was migrated from eclipse3.0 to the osgi core.

In Org. eclipse. in the source code of the osgi project, you can see that in addition to the osgi interface and Framework implementation, it also includes the adaptor interface and default adaptor (defaultadaptor), eclipse adaptor (eclipseadaptor) implementation, and console implementation ), additional functions such as service extension, bundle component resolution (Resolver), and bundle JAR File validation.

In actual use, you can use the JAR file to run the osgi framework (refer to the establishment of the osgi runtime environment below ). As a product-level application, many system-level parameters can be configured for users to adjust the operating behavior of the system to meet the requirements of different environments. Similarly, the Equinox runtime environment provides a large number of running parameters for users to choose from. There are two main methods to configure the Equinox runtime environment parameters: one is to use JVM environment variables, and the other is to use the Equinox configuration file (config. INI ).

After obtaining the org. Eclipse. osgi _ <version>. jar file, you can start the JAR file using the command line. The main class for storing the JAR file is org. Eclipse. Core. runtime. adaptor. eclipsestarter.

Java-jar org. Eclipse. osgi_3.3.1.r33x_v20070828.jar

The user will find that the program exits immediately after execution, and there is no output on the console. This is because there is no code function that can run continuously. After the framework is started, it exits from the main thread. Next, we will provide a detailed process for building the osgi runtime environment.

4. Build equinox osgi runtime environment 4.1 The original osgi Environment

Download the Equinox osgi framework from the eclipse website. Download it to the C:/equinox directory. The equinox version used in this article is 3.3.1. When you run the JAR file directly from the command line, the program will exit immediately after execution. To better understand the features of the Equinox osgi framework, we add JVM parameters during execution"Osgi. Console". As shown in:

After you run "Java-dosgi. Console-jar org. Eclipse. osgi_3.20.r33x_v20070828.jar", the system displays the "osgi>" command input prompt. Enter the "SS" command and press Enter. You can see the information of "framework is launched. At the same time, the following shows the bundle list started by the system. The ID column is the unique running ID of the bundle in the osgi runtime environment, and the State column is the current status of the bundle, the bundle column displays the symbolicname of the bundle component.

The osgi framework is running.

The equinox osgi console provides many commands for interacting with the osgi framework. You can enter any internal command characters other than the osgi console, and the control will display all the commands provided by the Equinox console. As follows:

Run the "services" command to view all service information released in the current osgi framework.

4.2 deploy bundle to the osgi environment using running parameters

Download the Equinox SDK and copy the org. Eclipse. osgi. services_3.1.200.v20070605.jar file under the Plugins directory to the C:/equinox directory. Modify the command line running parameters as follows:

Java-dosgi. Console-dosgi. bundles = org. Eclipse. osgi. services_3.1.200.v20070605.jar-jar org. Eclipse. osgi_3.20.r33x_v20070828.jar

Run this command. The system running result is shown in:

The running result shows that the JVM parameter "-dosgi. bundles = org. Eclipse. osgi. services_3.1.200.v20070605.jar" deploys the org. Eclipse. osgi. Services component to the osgi runtime environment. In this case, the component Status is "resolved", that is, the component is parsed by the framework but not started. If you want the component to start when it is loaded, you can modify the preceding parameters:

-Dosgi. bundles = org. Eclipse. osgi. services_3.1.200.v20070605.jar @ 2: Start.

"@ 2" indicates the start level of the component. ":" the "Start" indicates that the component is started after being loaded. The output result is as follows:

It can be seen that the deployed org. Eclipse. osgi. Services component is started by the osgi framework after being loaded, and its status is "active ".

4.3 deploy bundle to the osgi environment as a configuration file

From the above deployment bundle method, it can be seen that when multiple bundle are deployed, the JVM parameter configuration method is not available. Equinox osgi supports reading the loaded bundle from the configuration file. The following shows how to deploy multiple bundle using the configuration file.

Copy the org. Eclipse. osgi. util_3.1.200.v20070605.jar file under the Plugins directory of equinox SDK to the C:/equinox directory.

Equinox osgi provides the environment variable "osgi. configuration. Area", which specifies the storage path of the config. ini configuration file. In the C:/equinox directory, add the config. ini file and add the following content to the file:

Osgi. bundles = org. Eclipse. osgi. services_3.1.200.v20070605.jar @ 2: Start, org. Eclipse. osgi. util_3.1.200.v20070605.jar

Modify the startup Command Behavior of the osgi framework:

Java-dosgi. Console-dosgi. configuration. Area =.-jar org. Eclipse. osgi_3.20.r33x_v20070828.jar

The output result after the preceding command is executed is shown in:

5. Use eclipse launcher to start equinox osgi

Users who are familiar with the eclipse idea environment will visit the 3.2.pdf (package 3.2.pdf). The eclipse.exe and startup. Jar files are stored in the prefix seinstallation directory to start the eclipse runtime environment. Starting from version 3.3, equinox splits startup. jar into two different bundle (fragment) and places them in the Plugins directory. You can download launcher from the Equinox site. The launcher of version 3.3.1 released after the download includes the following two components:

Org. Eclipse. Equinox. launcher_1.0.1.r33x_v20070828.jar

Org. Eclipse. Equinox. launcher. win32.win32. x86_1.0.1.r33x_v20070828 [Directory]

Before performing the following operations, we need to adjust the directory structure of C:/equinox and add the "configuration" and "plugins" directories under the directory, transfer all bundle components (including directories) to the Plugins directory. the INI file is transferred to the configuration directory, and the "eclipse.exe" file in the launcher package is copied to the C:/equinox directory. The directory structure is as follows:

Shows the contents in the Plugins directory:

Modify the command line osgi framework startup command:

Eclipse.exe-console-noexit

After running this command, enter the "SS" command in the pop-up console. The output result is as follows:

5.1 use the eclipse. ini file

The parameters required for running the producer. Users should place the INI file in the directory where eclipse.exe is located.

Add the eclipse. ini file under the C:/equinox directory and add the following content to the file:

-Console

-Noexit

Click the eclipse.exe program icon to start the Equinox osgi runtime environment. Shows the program running result:

So far, the complete operating environment of equinox osgi has been set up. To publish a new bundle to this environment, you only need to modify the config. ini file in the configuration directory and add the new bundle to the osgi. bundles parameter.

6. FAQs

In the above steps, you will find that some error log files are generated in the configuration directory. If you find the following content in the log:

Java. Lang. illegalstateexception: unable to acquire Application Service. Ensure that the org. Eclipse. Core. runtime bundle is resolved and started (see config. INI ).
At org. Eclipse. Core. runtime. Internal. adaptor. eclipseapplauncher. Start (eclipseapplauncher. Java: 72)
At org. Eclipse. Core. runtime. adaptor. eclipsestarter. Run (eclipsestarter. Java: 363)
At org. Eclipse. Core. runtime. adaptor. eclipsestarter. Run (eclipsestarter. Java: 176)
At sun. Reflect. nativemethodaccessorimpl. invoke0 (native method)
At sun. Reflect. nativemethodaccessorimpl. Invoke (nativemethodaccessorimpl. Java: 39)
At sun. Reflect. delegatingmethodaccessorimpl. Invoke (delegatingmethodaccessorimpl. Java: 25)
At java. Lang. Reflect. method. Invoke (method. Java: 585)
At org. Eclipse. Equinox. launcher. Main. invokeframework (main. Java: 508)
At org. Eclipse. Equinox. launcher. Main. basicrun (main. Java: 447)
At org. Eclipse. Equinox. launcher. Main. Run (main. Java: 1173)

You can add the following configuration in the config. ini file:

Eclipse. ignoreapp = true

7. Summary

In the above section, we have introduced in detail the composition of the Equinox osgi environment and the construction process. In the next document, we will give a detailed introduction to the Equinox osgi runtime parameters, and provide a way for the osgi framework to automatically discover deployed osgi bundle without frequently modifying the configuration file.

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.