Customized Karaf development and debugging environment based on MAVEN high-speed construction

Source: Internet
Author: User
Tags xmlns netbeans
A customized KARAF development debugging environment based on MAVEN quick build
purpose of this article

The Apache Karaf Project provides developers and architects with a convenient foundation to run and deploy frameworks in the development of OSGi-based component framework applications. With Karaf's feature definition and KAR packaging, developers can freely define the grouping of OSGi bundles and customize fine-grained packaging definitions on demand, and when the system is released, by freely combining these feature and Kar, you can quickly publish targeted products or specific release packages.

Combined with MAVEN, KARAF provides a convenient and fast solution for user-based modular development, testing, integration, and continuous delivery of OSGi bundles.

This article provides a solution for the main discussion of how to quickly build a maven-based custom KARAF development debugging environment in the development phase, which can be referenced by developers who want to customize and crop the Karaf configuration environment. Karaf Conceptual Basis

For the features of the KARAF project for the OSGi Foundation operating environment, please refer to its official website. Here, I focus on Karaf's feature definition and KAR packaging. feature definition of Karaf

The feature concept of Karaf can be regarded as a subsystem implementation of a system. We know that OSGi is developed based on bundles and service, and that granular control of bundles requires developers to control their own experience based on project and system functionality. In a large system, there may be hundreds of bundles, and if so many bundles converge, how to differentiate and maintain will be a huge challenge, which often leads some developers and architects to be deterred by the modularity of OSGi. With the feature definition of Karaf, the OSGi bundle of the smallest unit can be aggregated together to form a functional feature based on functional parts, and multiple feature can be aggregated together to form a large feature, eventually all OSGi Bundles in an orderly combination, you can form a clear, reusable functional feature, to achieve the real modular development of the system and the reuse of components.



Now, let's look at a karaf feature definition:

<feature resolver= "(OBR)" description= "Implementation of the OSGI HTTP Service" version= "3.0.0-snapshot" name= "http" >
        <feature version= "3.0.4-snapshot" >pax-http</feature>
        <bundle start-level= ">MVN" :org.apache.karaf.http/org.apache.karaf.http.core/3.0.0-snapshot</bundle>
        <bundle start-level= "30" >mvn:org.apache.karaf.http/org.apache.karaf.http.command/3.0.0-SNAPSHOT</bundle>
    </feature>

As you can see from this feature definition, this feature defines the functionality of the HTTP service provided in OSGi, feature has Karaf two HTTP function-related bundles, and this feature is also for ops4j pax A Web project provides a set of bundles consisting of feature "Pax-http" with dependencies.

When Karaf runs, if this feature is loaded (in the standard feature Library of Karaf) and its dependent pax-http feature (in the Pax-web-features Library), specify the start HTTP featue , the set of related bundles is automatically loaded and started when Karaf starts. karaf kar Packaging

Karaf's KAR packaging functionality exists in the Karaf Karaf-maven-plugin plug-in. With this plug-in, Karaf can package all bundles and their dependencies in the featue definition into a compressed file with the suffix of. Kar to form a redistributable package. With the Karaf-maven-plugin plugin in conjunction with other plugins related to MAVEN packaging, the user can freely define the structure of the release package.

For multiple defined Kar bundles, maven dependencies can be packaged together in a final MAVEN release project to form a release package for a product.
KARAF Custom Debug Environment building process based on Maven

The following is a brief description of the build process for the MAVEN-based KARAF custom debugging environment. Often, based on OSGi development, developers often rely on Eclipse's plug-in development environment, in fact, MAVEN-based OSGi plug-in development (Felix's Maven-bundle-plugin plugin) is also convenient, fast and efficient, and is not limited by the development environment. MAVEN-based OSGi development, where NetBeans Ide,netbeans is recommended to have native support for MAVEN projects, can automatically parse Maven's POM build project.

The first step is to configure the dependency and startup configuration for Karaf in the POM

<?xml version= "1.0" encoding= "UTF-8"?> <project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "http ://www.w3.org/2001/XMLSchema-instance "xsi:schemalocation=" http://maven.apache.org/POM/4.0.0/http Maven.apache.org/xsd/maven-4.0.0.xsd "> <modelVersion>4.0.0</modelVersion> <parent> &L T;artifactid>karaf</artifactid> <groupId>ossu.sandbox.karaf</groupId> <version> 2.0.0-snapshot</version> </parent> <groupId>ossu.sandbox.karaf</groupId> <artifacti  D>karaf.launcher</artifactid> <packaging>pom</packaging> <name>ossu Sandbox:: Karaf:: Launcher</name> <description>run Karaf instance or debug Karaf instance</description> <de
            Pendencies> <dependency> <groupId>org.apache.karaf.features</groupId>
      <artifactId>framework</artifactId>      <type>kar</type> </dependency> <dependency> <!--scope is run Time so the feature repo are listed in the Features service config file, and features could be installed using T
            He karaf-maven-plugin configuration-<groupId>org.apache.karaf.features</groupId> <artifactId>standard</artifactId> <classifier>features</classifier> < type>xml</type> <scope>runtime</scope> </dependency> <dependency 
            > <!--scope is runtime so the feature repo are listed in the Features service config file, and features may installed using the Karaf-maven-plugin configuration--and <groupid>org.apache.kara F.features</groupid> <artifactId>spring</artifactId> <classifier>features&
     Lt;/classifier>       <type>xml</type> <scope>runtime</scope> </dependency> <dependency> <groupId>ossu.sandbox.karaf</groupId> <artifactid>karaf .boilerplate.framework</artifactid> <type>kar</type> <version>${project.ve rsion}</version> </dependency> </dependencies> <build> <plugins&gt
            ; <plugin> <groupId>org.apache.karaf.tooling</groupId> <artifactid>k
                        Araf-maven-plugin</artifactid> <executions> <execution>
                        <id>process-resources</id> <phase>process-resources</phase>
                        <goals> <goal>install-kars</goal> </goals> </execution> </executions> &L T;configuration> <installedFeatures> <feature>wrapper</featu re> </installedFeatures> <bootFeatures> &lt
                        ;feature>framework</feature> <feature>standard</feature>
                        <!--<feature>obr</feature>--> <feature>region</feature> <!--<feature>spring</feature>--> </bootfeatur
                es> </configuration> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactid>exec-maven-plugin</arti
             Factid>   <executions> <execution> <goals>
                <goal>exec</goal> </goals> </execution> </executions> <configuration> <executable>java</executable&
                    Gt

                        <workingDirectory>${project.basedir}/target/assembly</workingDirectory> <arguments> <argument>-classpath</argument> <argument>${project.bas edir}/target/assembly/conf${path.separator}${project.basedir}/target/assembly/lib/karaf-jaas-boot.jar${ path.separator}${project.basedir}/target/assembly/lib/karaf-jmx-boot.jar${path.separator}${project.basedir}/ Target/assembly/lib/karaf-org.osgi.core.jar${path.separator}${project.basedir}/target/assembly/lib/karaf.jar </argument> <aRgument>-xmx512m</argument> <argument>-XX:MaxPermSize=512m</argument> <argument>-dkaraf.startremoteshell=true</argume Nt> <argument>-Djava.net.preferIPv4Stack=true</argument> &L T;argument>-dderby.system.home=${project.basedir}/target/assembly/data/derby</argument> & Lt;argument>-dderby.storage.filesynctransactionlog=true</argument> <argument>-Dcom. Sun.management.jmxremote</argument> <argument>-dkaraf.startlocalconsole=true</argum Ent> <argument>-djline.windowsterminal.directconsole=false</ar
                        Gument> <argument>-Dkaraf.home=${project.basedir}/target/assembly</argument><argument>-Dkaraf.base=${project.basedir}/target/assembly</argument> <argument>- Dkaraf.etc=${project.basedir}/target/assembly/etc</argument> <argument>-dkaraf.instanc Es=${project.basedir}/target/assembly/instances</argument> <argument>-djava.io.tmpdir= ${project.basedir}/target/assembly/data/tmp</argument> <argument>-djava.endorsed.dirs= ${project.basedir}/target/assembly/lib/endorsed</argument> &LT;ARGUMENT&GT;-DKARAF.DATA=${PR Oject.basedir}/target/assembly/data</argument> <argument>-djava.util.logging.config.fi
                        
                        Le=${project.basedir}/target/assembly/etc/java.util.logging.properties</argument>
                        <!--Debug configuration--<argument>-Xdebug</argument> <argUment>-djava.compiler=none</argument> <argument>-xrunjdwp:transport=dt_socket,serve R=y,suspend=n,address=5005</argument> <argument>org.apache.karaf.main.main</argume                              
        nt> </arguments> </configuration> </plugin> </plugins> </build> </project>

With this pom, we can start Karaf and debug in a MAVEN environment. Here is a detailed explanation:

1) Dependent part

Mainly includes the dependency on the Karaf framework Kar, which is the Kar release package for the KARAF framework, which relies on it, at run time, Karaf's underlying directory structure will be created (under the target/assembly of the project where the Pom is located);

Depending on the standard feature Library of Karaf and the Spring feature library, by relying on these two feature libraries, KARAF will be able to find specific feature definitions in these two feature libraries at runtime.

The dependence on the Kar project of ossu.sandbox.karaf:karaf.boilerplate.framework (this kar is a specific crop of Karaf, as discussed later).

2) Compile and run part

The compilation run section consists of two Maven plugins: Karaf-maven-plugin and Exec-maven-plugin.

Karaf-maven-plugin

This plugin packages dependencies (jars, Kar, and so on), generates a release Kar package, and can specify which feature to start

<bootFeatures>
  <feature>framework</feature>
  <feature>standard</feature>
  <!--<feature>obr</feature>-->
  <feature>region</feature>
  <!--< Feature>spring</feature>-->                    
</bootFeatures>

Exec-maven-plugin

This plug-in is used to launch a Java virtual machine in a MAVEN project where the Karaf startup parameters are configured and the Karaf is started through the Org.apache.karaf.main.Main portal.

3) Start Karaf

In the command line environment, enter:

MVN Clean Package Exec:exec

The output is as follows:



Start execution in the NetBeans IDE environment, as shown in the image below, right-click on the project and select Customize in the popup menu-target:



In the pop-up window, enter:

Clean Package Exec:exec

As shown in the figure below

Click "OK" to execute the results as shown below



points to note

1) Limited to space, for Karaf tailoring and customization, will be discussed in the following articles.

2) Karaf 5005 Debug port on startup, can be connected for code debugging

3) This sample engineering code is located under GitHub's Https://github.com/xqttrc/sandbox project

4) This project code is dependent on the parent project under the Https://github.com/xqttrc/nebula project, which can be compiled separately from the POM under this project, or can be adjusted on its own.

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.