osgi+camel+karaf运行环境搭建(2)

本文开始osgi运行环境后续搭建,上文介绍了几个运行组件与容器,本文将开始具体的代码编写。


root module

打开intellij新建maven工程,待maven工程全部生成完成之后,在pom.xml中添加以下内容。

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.build.compilerLevel>1.8</project.build.compilerLevel>

    <build.javadoc.version>2.9.1</build.javadoc.version>
    <build.bundle.version>2.3.7</build.bundle.version>
    <build.release.version>2.5.2</build.release.version>
    <build.resource.version>2.6</build.resource.version>
    <build.install.version>2.5.2</build.install.version>
    <build.compiler.version>3.1</build.compiler.version>
    <build.deploy.version>2.8.1</build.deploy.version>
    <build.source.version>2.2.1</build.source.version>
    <build.jar.version>2.4</build.jar.version>

    <org.slf4j.version>1.7.10</org.slf4j.version>
    <org.osgi.version>5.0.0</org.osgi.version>

    <karaf.version>4.0.4</karaf.version>
    <mysql.version>5.1.38</mysql.version>

    <environment>develop</environment>
  </properties>

  <repositories>
    <repository>
      <id>haizhi</id>
      <name>Haizhi</name>
      <url>http://nexus.haizhi.com/content/groups/public</url>
    </repository>
  </repositories>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.14.8</version>
        <scope>provided</scope>
      </dependency>
      <dependency>
        <groupId>org.osgi</groupId>
        <artifactId>org.osgi.core</artifactId>
        <version>${org.osgi.version}</version>
        <scope>provided</scope>
      </dependency>
      <dependency>
        <groupId>org.osgi</groupId>
        <artifactId>org.osgi.compendium</artifactId>
        <version>${org.osgi.version}</version>
        <scope>provided</scope>
      </dependency>

      <!-- Logging -->
      <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>${org.slf4j.version}</version>
      </dependency>

      <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>${org.slf4j.version}</version>
        <scope>test</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
    </dependency>

    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-simple</artifactId>
    </dependency>
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
    </dependency>
  </dependencies>

  <build>
    <defaultGoal>install</defaultGoal>

    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.karaf.tooling</groupId>
          <artifactId>karaf-services-maven-plugin</artifactId>
          <version>${karaf.version}</version>
          <executions>
            <execution>
              <id>service-metadata-generate</id>
              <phase>process-classes</phase>
              <goals>
                <goal>service-metadata-generate</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
        <plugin>
          <groupId>org.apache.felix</groupId>
          <artifactId>maven-bundle-plugin</artifactId>
          <version>${build.bundle.version}</version>
          <extensions>true</extensions>
          <executions>
            <execution>
              <id>bundle-manifest</id>
              <phase>process-classes</phase>
              <goals>
                <goal>manifest</goal>
              </goals>
            </execution>
          </executions>
        </plugin>

        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-resources-plugin</artifactId>
          <version>${build.resource.version}</version>
          <configuration>
            <includeEmptyDirs>true</includeEmptyDirs>
            <encoding>${project.build.sourceEncoding}</encoding>
          </configuration>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-install-plugin</artifactId>
          <version>${build.install.version}</version>
        </plugin>

      </plugins>
    </pluginManagement>

    <plugins>
      <!-- Maven Javadoc -->

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-install-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
      </plugin>
    </plugins>
  </build>

</project>

以上均是搭建环境所必须的相关依赖,因为本环境并不仅仅是进行几个osgi的example的编写,因此搭建环境比较复杂。在以上依赖添加完之后,还需要将pom.xml中的packaging改为pom,并且删去工程下的src文件夹,本工程为root模块,不需要写代码。


parent module

新建maven module为当前工程的子module,命名为parent,与上述module相同的是,parent同样是一个父module,因此删除目录下src文件夹,仅保留pom.xml,同时在pom.xml中添加如下内容:

 <properties>
        <docker.image.prefix>wbg.space</docker.image.prefix>

        <build.docker.version>0.3.6</build.docker.version>
        <docker.base.image>java8</docker.base.image>
        <docker.base.version>1.1.4</docker.base.version>

        <camel.version>2.15.2</camel.version>
        <pax.web.version>4.2.2</pax.web.version>
        <cxf.version>3.0.4</cxf.version>
        <shiro.version>1.2.4</shiro.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.apache.camel</groupId>
                <artifactId>camel-core</artifactId>
                <version>${camel.version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.camel</groupId>
                <artifactId>camel-blueprint</artifactId>
                <version>${camel.version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.camel</groupId>
                <artifactId>camel-servlet</artifactId>
                <version>${camel.version}</version>
            </dependency>

            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>javax.servlet-api</artifactId>
                <version>3.1.0</version>
                <scope>provided</scope>
            </dependency>

            <!-- Testing & Camel Plugin -->
            <dependency>
                <groupId>org.apache.camel</groupId>
                <artifactId>camel-test-blueprint</artifactId>
                <version>${camel.version}</version>
                <scope>test</scope>
            </dependency>

            <!-- logging -->
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>1.7.12</version>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
                <version>1.7.12</version>
            </dependency>
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>1.2.17</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>cn.com</groupId>
            <artifactId>features</artifactId>
            <version>1.0-SNAPSHOT</version>
            <classifier>features</classifier>
            <type>xml</type>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.karaf.shell</groupId>
            <artifactId>org.apache.karaf.shell.console</artifactId>
            <version>${karaf.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.core</artifactId>
            <version>4.3.1</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.karaf.features</groupId>
            <artifactId>framework</artifactId>
            <version>${karaf.version}</version>
            <type>kar</type>
        </dependency>
        <dependency>
            <groupId>org.apache.karaf.features</groupId>
            <artifactId>standard</artifactId>
            <version>${karaf.version}</version>
            <classifier>features</classifier>
            <type>xml</type>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.karaf.features</groupId>
            <artifactId>spring</artifactId>
            <version>${karaf.version}</version>
            <classifier>features</classifier>
            <type>xml</type>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.karaf.features</groupId>
            <artifactId>enterprise</artifactId>
            <version>${karaf.version}</version>
            <classifier>features</classifier>
            <type>xml</type>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.camel.karaf</groupId>
            <artifactId>apache-camel</artifactId>
            <version>${camel.version}</version>
            <classifier>features</classifier>
            <scope>runtime</scope>
            <type>xml</type>
        </dependency>
        <dependency>
            <groupId>org.apache.karaf.cellar</groupId>
            <artifactId>apache-karaf-cellar</artifactId>
            <version>4.0.0</version>
            <classifier>features</classifier>
            <type>xml</type>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.shiro</groupId>
            <artifactId>shiro-features</artifactId>
            <version>${shiro.version}</version>
            <classifier>features</classifier>
            <type>xml</type>
            <scope>runtime</scope>
        </dependency>

        <!--<dependency>-->
            <!--<groupId>cn.com</groupId>-->
            <!--<artifactId>features</artifactId>-->
            <!--<version>1.0-SNAPSHOT</version>-->
            <!--<scope>runtime</scope>-->
            <!--<type>xml</type>-->
        <!--</dependency>-->
        <!-- logging -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-resources-plugin</artifactId>
                    <extensions>true</extensions>
                    <executions>
                        <execution>
                            <id>copy-resources</id>
                            <phase>install</phase>
                            <goals>
                                <goal>copy-resources</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>target/assembly</outputDirectory>
                                <overwrite>true</overwrite>
                                <resources>
                                    <resource>
                                        <directory>../../assembly/develop</directory>
                                        <filtering>false</filtering>
                                    </resource>
                                    <resource>
                                        <directory>src/test/resources</directory>
                                        <filtering>false</filtering>
                                    </resource>
                                </resources>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.karaf.tooling</groupId>
                    <artifactId>karaf-services-maven-plugin</artifactId>
                    <version>${karaf.version}</version>
                    <executions>
                        <execution>
                            <id>service-metadata-generate</id>
                            <phase>process-classes</phase>
                            <goals>
                                <goal>service-metadata-generate</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.karaf.tooling</groupId>
                    <artifactId>karaf-maven-plugin</artifactId>
                    <version>${karaf.version}</version>
                    <extensions>true</extensions>
                    <executions>
                        <execution>
                            <id>process-resources</id>
                            <phase>verify</phase>
                            <goals>
                                <goal>assembly</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>package</id>
                            <phase>install</phase>
                            <goals>
                                <goal>archive</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <karafDirectory>${project.build.directory}/assembly</karafDirectory>
                        <startSsh>true</startSsh>
                        <keepRunning>true</keepRunning>
                        <deployProjectArtifact>false</deployProjectArtifact>
                        <includeBuildOutputDirectory>false</includeBuildOutputDirectory>
                        <includeProjectArtifact>true</includeProjectArtifact>
                        <includeTransitiveDependency>true</includeTransitiveDependency>
                        <includeHelpOption>true</includeHelpOption>
                        <bootFeatures>
                            <feature>wrap</feature>
                            <feature>config</feature>
                            <feature>system</feature>
                            <feature>package</feature>
                            <feature>shell</feature>
                            <feature>shell-compat</feature>
                            <feature>feature</feature>
                            <feature>deployer</feature>
                            <feature>ssh</feature>
                            <feature>log</feature>
                            <feature>bundle</feature>
                        </bootFeatures>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>install</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

以上基本就是我们当前需要添加的所有依赖,在当前还添加了个别项目中的模块,这些是在后续中将添加的,当前报错的地方可以先注释起来。

并且注意maven插件中的karaf-tooling这一个插件,这个就是提供osgi的运行容器karaf,在后文的编写中,这个将起到非常重要的作用,同时maven-resources-plugin这一个插件管理我们项目中其他资源的位置,在日后的编写中也将会提到这个。当然上文中也必少不了felix这一个插件,在后文中编写felix官网中的example时,这个将不时出现。


feature module

再次在root module下新建maven工程,命名为feature module,这一个尤其重要,这个module中,将对具体的feature进行管理,feature是一批bundle的集合,同时也在管理接下来中的子module中所需的其他feature依赖和bundle。

管理这些feature需要一个单独的xml配置文件,删除src下的main文件夹,保留resource文件夹,新建xml命名为feature.xml,添加以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<features name="karaf-swagger-${project.version}"
          xmlns="http://karaf.apache.org/xmlns/features/v1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.0.0
        http://karaf.apache.org/xmlns/features/v1.0.0">

</features>

现在这个feature.xml中没有管理任何featue,在后文中将会添加其他featue进来。现在是最基本的配置。

在新建完feature之后,在pom文件中添加以下内容:


    <properties>
        <deploy.file>${project.build.directory}/classes/features.xml</deploy.file>
    </properties>

    <build>
        <defaultGoal>install</defaultGoal>

        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>filter</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>resources</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.9.1</version>
                <executions>
                    <execution>
                        <id>attach-artifacts</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>${deploy.file}</file>
                                    <type>xml</type>
                                    <classifier>features</classifier>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

以上内容是指定feature.xml文件位置以及相应对该文件进行操作的插件,在以上完成之后,需要改当前pom的parent为parent module,同时在parent module中添加module为feature。


总结

以上完成之后,基本的环境搭建基本就完成了,具体的编码module的创建,还有karaf输出日志的的规定,将在下次博文中编写,本文仅只搭建基本的运行环境。

时间: 2024-08-07 15:49:23

osgi+camel+karaf运行环境搭建(2)的相关文章

osgi+camel+karaf运行环境搭建(1)

这几天一直在学习与加深osgi中的一些东西,又去看了下apache felix中的几个example,于是决定将felix中的一些example写出来,但是不在使用felix官网中那样运行,而是从新搭建一个osgi的运行环境进行相应的学习,在这使用了karaf作为osgi的运行容器,同时整合camel进来,因为在后续会有更多的osgi中的运用,因此,本次全部整合进来. 本文在此先对几个框架和容器进行相应介绍. karaf Karaf是2001年Apache旗下的一个开源项目.Karaf同时也是一

Apache Spark源码走读之12 -- Hive on Spark运行环境搭建

欢迎转载,转载请注明出处,徽沪一郎. 楔子 Hive是基于Hadoop的开源数据仓库工具,提供了类似于SQL的HiveQL语言,使得上层的数据分析人员不用知道太多MapReduce的知识就能对存储于Hdfs中的海量数据进行分析.由于这一特性而收到广泛的欢迎. Hive的整体框架中有一个重要的模块是执行模块,这一部分是用Hadoop中MapReduce计算框架来实现,因而在处理速度上不是非常令人满意.由于Spark出色的处理速度,有人已经成功将HiveQL的执行利用Spark来运行,这就是已经非常

Win2012 R2 IIS8.5+PHP(FastCGI)+MySQL运行环境搭建教程

这篇文章主要介绍了Win2012 R2 IIS8.5+PHP(FastCGI)+MySQL运行环境搭建教程,需要的朋友可以参考下 准备篇 一.环境说明: 操作系统:Windows Server 2012 R2 PHP版本:php 5.5.8 MySQL版本:MySQL5.6.15 二.相关软件下载: 1.PHP下载地址: http://windows.php.net/downloads/releases/php-5.5.8-nts-Win32-VC11-x86.zip 2.MySQL下载地址:

Ubuntu下nginx+uwsgi+flask的运行环境搭建

选择web framwork是个很艰难的事情, 主要分为轻量级和重量级框架. 由于没有搭建网站这种需要, 所以回避SSH, Django这种框架, 而选择一个轻量级框架. 自己也比较青睐python这门语言, 就选择了flask框架, nginx代理服务器享誉盛名, 所以拿来使用咯. 一. 开发环境搭建 采用离线安装方式, ubuntu开发环境(centos等环境类似) nginx 安装 $ wget http://nginx.org/download/nginx-1.6.0.tar.gz #仅

Win2012 R2 IIS8.5+PHP(FastCGI)+MySQL运行环境搭建wordpress博客教程

Win2012 R2 IIS8.5+PHP(FastCGI)+MySQL运行环境搭建教程 一.环境说明: 操作系统:Windows Server2012 R2 PHP版本:php 5.5.8 MySQL版本:MySQL5.6.15 二.相关软件下载: 1.PHP下载地址: http://windows.php.net/downloads/releases/php-5.5.8-nts-Win32-VC11-x86.zip 2.MySQL下载地址: http://cdn.mysql.com/Down

hadoop1学习系列1——运行环境搭建

1.VirtualBox 安装 恩,一路默认即可安装完毕. 2.宿主机网络环境配置(使用Host-Only模式,上网啥的不用改配置) 2.1 右击VirtualBox选择属性,更改网络IP设置 2.2 设置为Ip地址和子网掩码为如下属性:,点击确定.(注意Centos默认网段为56) 3. Centos6.4 运行环境设置(双击图标文件) 3.1 出现VIrtualBox界面 3.2 点击设置,将USB设备禁用(不启用啦) 3.3 网络模式选择Host-Only 3.3 点击确定. 一个搭建ha

OSGI的WEB开发环境搭建

第一步,搭建OSGI环境: 打开eclipse,点击run->run configration..,配置如下,点击run. 运行结果如下图所示:说明OSGI环境搭建完毕. 第二步:搭建基于OSGI的web开发环境 两种方式:第一种,勾选需要的Bundle,列表如下图 第二种,勾选如下,点击添加需要的Bundle,如下图 点击运行,结果如下: Web访问,显示如下信息,说明OSGI的Web环境搭建完毕. 第三步:编写一个简单的WEB服务验证结果(字典查询为例) 新建一个DictQuery插件工程,

基于IntelliJ IDEA 15.0.2的Tomcat7.0.69源码运行环境搭建

由于目前的工作内容调整,及重新进行职业规划,预备进行Tomcat源码学习. 一.准备资源: 1.Java的IDE工具使用:IntelliJ IDEA 15.0.2 版本 2.Tomcat源码使用:apache-tomcat-7.0.69-src.zip 版本 3.使用Maven环境:apache-maven-3.0.4 版本 4.JDK环境:使用 jdk1.7.0_51 版本 二.环境搭建 1.准备Tomcat源码环境 a.解压tomcat7.0.69源码压缩包 b.将tomcat7.0.69转

Windows7下的Java运行环境搭建过程图解

第一步:下载JDK 地址:http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html,(由于Sun于2009年被oracle收购所以网址是oracle的) 单击“Java Download”按钮. 选中“Accept License Agreement”单选按钮. 我们以Windows 64位操作系统为例,下载Windows X64版的jdk.单击“jdk-8u5-windows-x64.exe”直接