Ubuntu 22.04 安装 Apache Aries 指南

Ubuntu 22.04 安装 Apache Aries 指南:JDK 17 与 Maven 3.6.3 环境准备、Felix 7.0.5 运行时搭建、Aries Blueprint 1.10.3 部署及示例 bundle 安装与调用验证。

Apache AriesAries2026/10/14

Ubuntu 22.04 安装 Apache Aries 指南

目标:在 Ubuntu 22.04 服务器上从零搭建 OSGi 运行时环境,安装 Apache Aries Blueprint 1.10.3 组件,构建并部署一个服务装配示例(提供方与消费方两个 bundle),验证 Blueprint 运行时创建与服务可调用。

一、环境信息

1.1 组件说明

Apache Aries 是 OSGi Enterprise 编程模型的开源实现,覆盖 Blueprint、JPA、JMX 等企业级规范。Aries 本身不是独立进程,而是以 bundle 形式运行在 OSGi 运行时内部:运行时负责 bundle 生命周期与服务注册表,Aries Blueprint 扩展器负责解析 XML 装配描述并创建 Blueprint 运行时。

💡 技术拓展:OSGi 框架有多个实现,定位各有侧重——Apache Felix 轻量、适合嵌入式与学习调试;Apache Karaf 在 Felix/Equinox 之上提供远程 shell、热部署与特性管理,适合企业级集成;Eclipse Equinox 是 Eclipse 平台底层,与 Eclipse 生态深度绑定。三者均遵循 OSGi 规范,本文选用 Felix 7.0.5 作为宿主运行时。

1.2 服务器环境

项目值
操作系统Ubuntu 22.04.5 LTS(x86_64)
包管理器apt
内核与 CPU2 核 4 线程,x86_64
内存4 GB
磁盘可用 330 GB
运行账号root
网络可访问 repo.maven.apache.org 与 Maven 中央仓库

1.3 软件清单

软件版本说明
OpenJDK17.0.20.1运行环境(apt 安装 openjdk-17-jdk)
Maven3.6.3构建工具(apt 安装)
Apache Felix Framework7.0.5OSGi 运行时(org.apache.felix.main-7.0.5.jar)
Aries Blueprint1.10.3Blueprint 扩展器与核心实现
Aries Util1.1.3Aries 公共工具包
Aries Proxy1.1.1 / 1.0.6服务代理 API 与实现
slf4j1.7.36日志门面
示例 bundle1.0.0aries-blueprint-demo 与 aries-blueprint-consumer

二、安装 JDK 17

2.1 通过 apt 安装

apt-get update
apt-get install -y openjdk-17-jdk openjdk-17-jdk-headless unzip

2.2 验证结果

java -version
javac -version

真实回显:

openjdk version "17.0.20.1" 2026-08-18
OpenJDK Runtime Environment (build 17.0.20.1+1-1-22.04-Ubuntu)
OpenJDK 64-Bit Server VM (build 17.0.20.1+1-1-22.04-Ubuntu, mixed mode, sharing)
javac 17.0.20.1

验证通过:JDK 17 就绪,java 与 javac 版本一致。

三、安装 Maven

3.1 通过 apt 安装

apt-get install -y maven

3.2 验证结果

mvn -version

真实回显:

Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 17.0.20.1, vendor: Ubuntu, runtime: /usr/lib/jvm/java-17-openjdk-amd64

验证通过:Maven 3.6.3 运行在 JDK 17 之上,可直接编译 target 17 的工程。

四、准备 Felix 运行时与 Aries Blueprint 组件

4.1 下载 Felix Framework

Felix 官方发行 zip 已从 Apache 分发站点下架(实测返回 404),可从 Maven 中央仓库获取等价产物 org.apache.felix.main-7.0.5.jar(框架本体加启动器,与发行包内 bin/felix.jar 完全一致):

mkdir -p /opt/felix
cd /tmp
curl -sSL -o felix-main.jar \
  https://repo.maven.apache.org/maven2/org/apache/felix/org.apache.felix.main/7.0.5/org.apache.felix.main-7.0.5.jar
ls -l felix-main.jar

真实回显:

-rw-r--r-- 1 root root 781804 Oct 13 16:36 felix-main.jar

4.2 组织运行时目录

mkdir -p /opt/felix/bin /opt/felix/conf /opt/felix/bundle
cp /tmp/felix-main.jar /opt/felix/bin/felix.jar

写入最小配置 conf/config.properties(缺省此文件时启动器会提示 No config.properties found):

cat > /opt/felix/conf/config.properties <<'EOF'
felix.auto.deploy.action=install,start
felix.auto.deploy.dir=bundle
felix.log.level=4
org.osgi.framework.storage=felix-cache
EOF

4.3 放置 Aries Blueprint 组件

从 Maven 中央仓库下载 Aries Blueprint 运行所需的 16 个 bundle 到 /opt/felix/bundle:

cd /opt/felix/bundle
curl -sSL -O https://repo.maven.apache.org/maven2/org/apache/aries/blueprint/org.apache.aries.blueprint.core/1.10.3/org.apache.aries.blueprint.core-1.10.3.jar
curl -sSL -O https://repo.maven.apache.org/maven2/org/apache/aries/blueprint/org.apache.aries.blueprint.api/1.0.1/org.apache.aries.blueprint.api-1.0.1.jar
curl -sSL -O https://repo.maven.apache.org/maven2/org/apache/aries/util/org.apache.aries.util/1.1.3/org.apache.aries.util-1.1.3.jar
curl -sSL -O https://repo.maven.apache.org/maven2/org/apache/aries/proxy/org.apache.aries.proxy.api/1.1.1/org.apache.aries.proxy.api-1.1.1.jar
curl -sSL -O https://repo.maven.apache.org/maven2/org/apache/aries/proxy/org.apache.aries.proxy.impl/1.0.6/org.apache.aries.proxy.impl-1.0.6.jar
curl -sSL -O https://repo.maven.apache.org/maven2/org/apache/aries/quiesce/org.apache.aries.quiesce.api/1.0.0/org.apache.aries.quiesce.api-1.0.0.jar
curl -sSL -O https://repo.maven.apache.org/maven2/org/ow2/asm/asm/9.6/asm-9.6.jar
curl -sSL -O https://repo.maven.apache.org/maven2/org/slf4j/slf4j-api/1.7.36/slf4j-api-1.7.36.jar
curl -sSL -O https://repo.maven.apache.org/maven2/org/slf4j/slf4j-simple/1.7.36/slf4j-simple-1.7.36.jar
curl -sSL -O https://repo.maven.apache.org/maven2/org/apache/felix/org.apache.felix.gogo.command/1.1.2/org.apache.felix.gogo.command-1.1.2.jar
curl -sSL -O https://repo.maven.apache.org/maven2/org/apache/felix/org.apache.felix.gogo.jline/1.1.8/org.apache.felix.gogo.jline-1.1.8.jar
curl -sSL -O https://repo.maven.apache.org/maven2/org/apache/felix/org.apache.felix.gogo.runtime/1.1.4/org.apache.felix.gogo.runtime-1.1.4.jar
curl -sSL -O https://repo.maven.apache.org/maven2/org/apache/felix/org.apache.felix.bundlerepository/2.0.10/org.apache.felix.bundlerepository-2.0.10.jar
curl -sSL -O https://repo.maven.apache.org/maven2/org/jline/jline/3.13.2/jline-3.13.2.jar
curl -sSL -O https://repo.maven.apache.org/maven2/org/fusesource/jansi/jansi/1.18/jansi-1.18.jar
ls /opt/felix/bundle

真实回显:

asm-9.6.jar
jansi-1.18.jar
jline-3.13.2.jar
org.apache.aries.blueprint.api-1.0.1.jar
org.apache.aries.blueprint.core-1.10.3.jar
org.apache.aries.proxy.api-1.1.1.jar
org.apache.aries.proxy.impl-1.0.6.jar
org.apache.aries.quiesce.api-1.0.0.jar
org.apache.aries.util-1.1.3.jar
org.apache.felix.bundlerepository-2.0.10.jar
org.apache.felix.gogo.command-1.1.2.jar
org.apache.felix.gogo.jline-1.1.8.jar
org.apache.felix.gogo.runtime-1.1.4.jar
slf4j-api-1.7.36.jar
slf4j-simple-1.7.36.jar

4.4 首次启动验证

cd /opt/felix
java -jar bin/felix.jar

真实回显(Aries Blueprint 扩展器随框架启动并完成初始化):

Oct 13, 2026 4:31:44 PM org.jline.utils.Log logr
WARNING: Unable to create a system terminal, creating a dumb terminal (enable debug logging for more information)
[Blueprint Extender: 1] INFO org.apache.aries.blueprint.container.BlueprintContainerImpl - Blueprint bundle org.apache.aries.blueprint.core/1.10.3 has been started

Welcome to Apache Felix Gogo

g!

验证通过:Felix 7.0.5 启动成功,Aries Blueprint 扩展器已注册并创建自己的 Blueprint 运行时。

五、构建服务装配示例 bundle

5.1 工程结构

服务装配示例包含两个 bundle:提供方注册 Greeting 服务,消费方通过 Blueprint reference 注入并调用。

aries-src/
├── demo/pom.xml                                     # 提供方工程(packaging=bundle)
│   └── src/main/
│       ├── java/com/example/aries/api/Greeting.java
│       ├── java/com/example/aries/impl/GreetingImpl.java
│       └── resources/OSGI-INF/blueprint/demo.xml
└── consumer/pom.xml                                 # 消费方工程(packaging=bundle)
    └── src/main/
        ├── java/com/example/aries/consumer/GreetingClient.java
        └── resources/OSGI-INF/blueprint/consumer.xml

5.2 提供方 bundle

服务接口与实现:

package com.example.aries.api;

public interface Greeting {
    String greet(String name);
}
package com.example.aries.impl;

import com.example.aries.api.Greeting;

public class GreetingImpl implements Greeting {

    private String prefix = "Hello";

    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }

    @Override
    public String greet(String name) {
        return prefix + ", " + name + "!";
    }
}

Blueprint 装配描述 demo.xml:声明 bean 并注册为 OSGi 服务。

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">

  <bean id="greetingBean" class="com.example.aries.impl.GreetingImpl">
    <property name="prefix" value="Hello"/>
  </bean>

  <service ref="greetingBean" interface="com.example.aries.api.Greeting"/>

</blueprint>

demo/pom.xml 以 bundle 打包,用 maven-bundle-plugin 5.1.9 生成 OSGi 响应头,依赖 org.osgi.service.blueprint 1.0.2(provided)。

5.3 消费方 bundle

package com.example.aries.consumer;

import com.example.aries.api.Greeting;

public class GreetingClient {

    private Greeting greeting;

    public void setGreeting(Greeting greeting) {
        this.greeting = greeting;
    }

    public void init() {
        System.out.println("[consumer] " + greeting.greet("Aries Blueprint"));
    }
}

装配描述 consumer.xml:reference 声明对 Greeting 服务的依赖,bean 的 init-method 在服务就绪后触发调用。

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">

  <reference id="greetingRef" interface="com.example.aries.api.Greeting"/>

  <bean id="client" class="com.example.aries.consumer.GreetingClient"
        init-method="init">
    <property name="greeting" ref="greetingRef"/>
  </bean>

</blueprint>

5.4 构建

消费方依赖提供方的 api 包,先 install 提供方到本地仓库,再打包消费方:

cd /opt/aries-src/demo
mvn install -DskipTests
cd /opt/aries-src/consumer
mvn package -DskipTests
ls -l /opt/aries-src/demo/target/aries-blueprint-demo-1.0.0.jar
ls -l /opt/aries-src/consumer/target/aries-blueprint-consumer-1.0.0.jar

真实回显:

-rw-r--r-- 1 root root 4447 Oct 13 16:31 /opt/aries-src/demo/target/aries-blueprint-demo-1.0.0.jar
-rw-r--r-- 1 root root 4045 Oct 13 16:31 /opt/aries-src/consumer/target/aries-blueprint-consumer-1.0.0.jar

5.5 验证 MANIFEST

查看提供方 bundle 的 OSGi 响应头:

unzip -p /opt/aries-src/demo/target/aries-blueprint-demo-1.0.0.jar META-INF/MANIFEST.MF

真实回显关键行:

Bundle-SymbolicName = com.example.aries.blueprint.demo
Bundle-Version = 1.0.0
Bundle-Blueprint = OSGI-INF/blueprint/demo.xml
Export-Package = com.example.aries.api;version="1.0.0",com.example.aries.impl;version="1.0.0";uses:="com.example.aries.api"
Export-Service = com.example.aries.api.Greeting;osgi.service.blueprint.compname=greetingBean
Import-Package = com.example.aries.api;version="[1.0,2)",java.lang,java.lang.invoke,org.osgi.service.blueprint;version="[1.0.0,2.0.0)"
Require-Capability = osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=17))"

验证通过:Bundle-Blueprint 指向装配描述,Export-Service 声明服务导出,构建产物符合 OSGi 规范。

六、部署 Blueprint 服务并验证

6.1 安装 bundle

在 Felix Gogo shell 中安装两个 bundle:

g! install file:/opt/aries-src/demo/target/aries-blueprint-demo-1.0.0.jar
Bundle ID: 17
g! install file:/opt/aries-src/consumer/target/aries-blueprint-consumer-1.0.0.jar
Bundle ID: 19

6.2 启动并观察 Blueprint 运行时

g! start 17
[Blueprint Extender: 2] INFO org.apache.aries.blueprint.container.BlueprintContainerImpl - Blueprint bundle com.example.aries.blueprint.demo/1.0.0 has been started
g! start 19
[consumer] Hello, Aries Blueprint!
[Blueprint Extender: 1] INFO org.apache.aries.blueprint.container.BlueprintContainerImpl - Blueprint bundle com.example.aries.blueprint.consumer/1.0.0 has been started

验证结果:提供方与消费方的 Blueprint 运行时均已创建,消费方通过注入的 Greeting 服务输出调用结果。

6.3 检查 bundle 状态

g! lb
START LEVEL 1
   ID|State      |Level|Name
    0|Active     |    0|System Bundle (7.0.5)|7.0.5
    1|Active     |    1|org.objectweb.asm (9.6.0)|9.6.0
    2|Active     |    1|file:/opt/felix/bundle/blueprint-parser-1.6.0.jar (0.0.0)|0.0.0
    3|Active     |    1|jansi (1.18.0)|1.18.0
    4|Active     |    1|JLine Bundle (3.13.2)|3.13.2
    5|Active     |    1|Apache Aries Blueprint API (1.0.1)|1.0.1
    6|Active     |    1|Apache Aries Blueprint Core (1.10.3)|1.10.3
    7|Active     |    1|Apache Aries Proxy API (1.1.1)|1.1.1
    8|Active     |    1|Apache Aries Proxy Service (1.0.6)|1.0.6
    9|Active     |    1|Apache Aries Quiesce API (1.0.0)|1.0.0
   10|Active     |    1|Apache Aries Util (1.1.3)|1.1.3
   11|Active     |    1|Apache Felix Bundle Repository (2.0.10)|2.0.10
   12|Active     |    1|Apache Felix Gogo Command (1.1.2)|1.1.2
   13|Active     |    1|Apache Felix Gogo JLine Shell (1.1.8)|1.1.8
   14|Active     |    1|Apache Felix Gogo Runtime (1.1.4)|1.1.4
   15|Active     |    1|slf4j-api (1.7.36)|1.7.36
   16|Active     |    1|slf4j-simple (1.7.36)|1.7.36
   17|Active     |    1|aries-blueprint-demo (1.0.0)|1.0.0
   19|Active     |    1|aries-blueprint-consumer (1.0.0)|1.0.0

6.4 检查服务注册表

g! inspect cap service 17
com.example.aries.blueprint.demo [17] provides:
-----------------------------------------------
service; com.example.aries.api.Greeting with properties:
   osgi.service.blueprint.compname = greetingBean
   service.bundleid = 17
   service.id = 33
   service.scope = bundle
   Used by:
      com.example.aries.blueprint.consumer [19]
service; org.osgi.service.blueprint.container.BlueprintContainer with properties:
   osgi.blueprint.container.symbolicname = com.example.aries.blueprint.demo
   osgi.blueprint.container.version = 1.0.0
   service.bundleid = 17
   service.id = 34
   service.scope = singleton

验证结果:demo bundle 注册了两个服务——Greeting 服务(正在被 consumer 使用)与 BlueprintContainer 服务,服务装配闭环成立。

6.5 停止与卸载

g! stop 17
g! uninstall 19
[pipe-uninstall 19] INFO org.apache.aries.blueprint.container.BlueprintExtender - Destroying container for blueprint bundle com.example.aries.blueprint.consumer/1.0.0

验证结果:卸载消费方时 Aries 同步销毁其 Blueprint 运行时,资源清理完整。

6.6 关闭运行时

g! stop
[FelixShutdown] INFO org.apache.aries.blueprint.container.BlueprintExtender - Destroying container for blueprint bundle com.example.aries.blueprint.consumer/1.0.0
[FelixShutdown] INFO org.apache.aries.blueprint.container.BlueprintExtender - Destroying container for blueprint bundle com.example.aries.blueprint.demo/1.0.0
[FelixShutdown] INFO org.apache.aries.blueprint.container.BlueprintExtender - Destroying container for blueprint bundle org.apache.aries.blueprint.core/1.10.3
g! gosh: stopping framework

验证结果:框架关闭时三个 Blueprint 运行时依次销毁,无残留服务。

七、参考链接