To build an OSGi run-time compilation environment using JDK6 dynamic compilation components

Source: Internet
Author: User
Tags command line

But we know that one of the most troublesome steps in developing a Bundle in an OSGi environment is to build a compilation environment. Even with the efficient development tools such as Eclipse, maintaining a compilation environment is cumbersome due to the sheer number of Bundle and the multiplicity of versions of the same Bundle. Often we need to develop two times for an OSGi Bundle, just a small change that takes a lot of time to build a compilation environment for this program. We are eager to have a run-time compilation environment that simplifies these steps and compiles the code with dependencies that exist in the environment.

This article describes the operational characteristics of OSGi, the way in which Bundle is dependent, and the dynamic compilation capabilities provided by JDK6, followed by step-by-step information on how to build a development environment that can be run-time compilation, and finally, through IBM System Director as an example, to develop Bund Le Install on the above demo to give the reader an intuitive experience. This article assumes that the reader has a certain OSGi basic knowledge and Java basics. After reading this article, if the reader has an OSGI runtime environment and the Java source code that you want to compile to run the environment, you can build the module that compiles the bytecode file for release and two development using this running environment.

Figure 1 depicts the traditional OSGi-based application architecture:

Figure 1. OSGi-based application architecture

To implement the functionality described in the article, the application only needs to meet the following system requirements:

An implementation version based on any OSGi4, such as Knopflerfish or Equinox.

Run JDK version 6.0 or more.

Figure 2 provides an overview of the purpose described in this article:

Figure 2. Runtime Compilation Environment model

where Bundle1, 2, and so on are the existing Bundle in the OSGi runtime environment, where OSGi has loaded their corresponding jar packages or bytecode files. The brown block diagram is the OSGi runtime dynamic compilation Bundle we want to make.

User enters Java source code (in command line or file form)

The dynamic compilation module scans all Bundle and saves all Jar and class files in the Run-time environment as compile-time dependencies.

Dynamic compilation using the dynamic compilation component provided by JDK6

Write your own Javafileobject object, and specify the compilation destination of the Standardjavafilemanager (these are JDK6 the content of the dynamic compilation component will be described in detail later) to compile the Java bytecode file

Optionally, send the class file to the specified mailbox to complete the run-time compilation process.

Let's take a look at how to build this Run-time compilation Bundle using the JDK6 Dynamic compilation component and the related functionality provided by OSGi. Before that, however, it is necessary to understand the way the communication between the Bundle.

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.