Version HelloWorld

Source: Internet
Author: User

This article mainly describes the implementation mechanism of the OSGI framework using spring.dm2.0, creating an OSGi HelloWorld demo program, and understanding SPRING.DM.

Environment Description:
Project Version
Eclipse 3.7.x
Jdk 1.6.x Spring-osgi-2.0.0.m1-with-dependencies
First, the Environment preparation

To extract the spring-osgi-2.0.0.m1-with-dependencies into a folder, you can see the following directories:

When you click menu in Eclipse: File->import, an imported dialog box appears, such as

With "Plug-ins and Fragments" selected, click "Next>" and the Import Options dialog box appears, as

Select "Directory" in the "Import from", click on the "Browse" in the back of the "Dist" folder in the folder directory where we just unzipped, then click "Next>",

The Import dialog box appears, import the jar package as selected, click "Finish",

Then with the above steps, import spring-osgi-2.0.0.m1-with-dependencies unzip the lib in the directory, select the jar package as shown, click "Finish" to complete the import

A total of 15 packages were imported from the Dist and LIB directories,

    1. Org.springframeork.osgi.bundle.core
    2. Org.springframeork.osgi.bundle.extender

These 3 packets are the core package of SPRING.DM, the Extender package completes the service release and the injection function, it will find the XML file in the spring directory under the Meta-inf to complete the configuration work;

These packages are org.apache.commons.logging dependent packages, otherwise you will be prompted with the following error:

Reason:missing constraint:import-package:org.apache.commons.logging; Version= "[1.1.1,2.0.0)"

Finally you can see the following results in the Package Explorer view:

We're ready to go. Package reference Environment

Ii. Configuring OSGi Run Configuration

In the Eclipse menu operation: Run->run configurations, the Run Configuration window will appear, right click on "OSGi Framework" in the left panel, click "New", as shown in

The Run Configuration dialog box appears, as shown in;

In workspace, select the bundle required to run, the red rectangular box shown, select an OSGi and a loggin package in target platform, as shown, click CheckBox "Only show Selected ", should and like, click" Validate Bundles "to verify that the binding is correct, we first set the name of the Run configuration to: RUN_SPRING.DM, click on the" Apply "button to save, and finally click" Run button, which runs the configuration that you can see in the console window, such as:

There is a warning ( to resolve the warning issue in the building of web development environment), first ignore, press ENTER in console, then enter: SS, view plug-in running status as shown in

This means that our SPRING.DM environment has been configured, and then we're going to have a HelloWorld!

Iii. Creating a HelloWorld Demo

In the Eclipse menu: File->new->project ..., select as shown in the New Project dialog box (plug-in project)

Click "Next>" in the New Project dialog box, select as shown

In the change the project name to:, select "An OSGi framework:standard" in "Target Platform", click "next>"

In the settings: Provider, then click "Finish" to complete the creation of the project, the new project is created, as shown in the red box

Since we develop do not need to Activator, so the src under the bread "" in the "" removed, deleted as shown

A warning appears in the MANIFEST.MF file in Meta-inf, and we double-click the open MANIFEST.MF file, select the Manifest tab, as shown in

A warning flag appears in the, as shown in the long red rectangle, we delete the line and save it, otherwise we will not find the activator error. The current project looks like this:

In the middle src under the bread package Create a HelloWorld Java class file, as shown in

In the HelloWorld class, write start and stop two methods, print out the following state, as shown below,

In the Meta-inf folder in the project, create a new spring folder and create a new Helloworld.xml file in the Spring folder, as shown in:

The contents of the Helloworld.xml file are as follows:

<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "Http://"  Xmlns:xsi= "Http://"  xsi:schemalocation= " Schema/beans ">    <!--bean definition--  < Bean name= "Hello" class= "" init-method= "Start" destroy-method= "Stop" >  </ Bean>  </beans>

This bean's configuration is the same as when we use spring configuration, when we start HelloWorld, we call the Start method, the console will appear "I am booting", when we stop HelloWorld, we will call the Stop method, the console will print out "I'm shutting down."

Well, our HelloWorld is done.

Four, running HelloWorld

In the Eclipse menu: Run->run configurations ..., the following interface appears, as shown in

In Workspace the new HelloWorld package is selected, as shown in, click the "Run" button to run, I can see the following results, as shown in:

We enter in the console, then input: ss, enter, the status of the query, the results are as follows

In the HelloWorld we have started, we use the command to stop the HelloWorld, enter stop 23 in the console, carriage return

We can see in the console that the output is "I'm shutting down" and enter SS to query the status as shown:

As can be seen in the HelloWorld, we are already in the resolved state.

At present we have succeeded in HelloWorld out!

Version HelloWorld

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: 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.