JBoss OSGi用户指南(第二章:Getting Started)
2 Getting Started
2.1 本章内容
This chapter takes you through the first steps of getting JBoss OSGi and provides the initial pointers to get up and running.
本章将会指导你使用JBoss OSGi,并指导你建立并运行你的环境。
l Download the Distribution
l 下载发布版本
n Running the Installer
n 运行安装
l Activating the Subsystem
l 激活子系统
l Provided Examples
l 示例
l Bundle Deployment
l Bundle部署
l Managing installed Bundles
l 管理已经部署的Bundle
n Felix Web Console
n Felix Web控制台
2.2 下载发行版
Starting from WildFly-8.0.0.Alpha3, OSGi support is not part of WildFly anymore.
从WildFly-8.0.0.Alpha3本本开始,OSGi不再是WildFly的一部分。
JBoss OSGi project provides examples, documentation and the subsystem that adds OSGi functionality to WildFly.
JBoss OSGi项目提供示例,文档和子系统来指导将OSGi的功能添加到WildFly。
JBoss OSGi is distributed as an IzPack installer archive. The installer is available from the JBoss OSGi download area.
JBoss OSGi是以IzPack安装包的形式发行的。安装包可以从JBoss OSGi网站上面下载。
WildFly can be downloaded from the WildFly download area.
WildFly可以从WildFly网站下载。
2.2.1 执行安装包
To run the Project Distribution installer execute the following command:
执行如下的命令来运行安装包:
java -jar jboss-osgi-installer-2.1.0.jar |
The installer first shows a welcome screen
首先看到的是一个环境界面
Then you select the installation path for the JBoss OSGi distribution. This is the directory where you find binaries, sources, examples and documentation.
然后再下面的界面中选择你的安装目录。在这个目录中包含了二进制可执行文件,源代码,示例及文档。
You can then select whether you want to install the OSGi subsystem into an existing WildFly build
你可以选择是否安装OSGi模块到已经安装的WildFly系统中
2.3 激活OSGi模块
By default the OSGi subsystem is activated lazily. It means that the framework will not start up unless you deploy an OSGi bundle. You can activate the OSGi subsystem explicitly by setting the activation property to 'eager'.
OSGi模块模式是懒加载的。也就是说这个模块只有在你部署了Bundle之后才会启动。你可以通过将activation设置为‘eager’来显式的激活你的系统。
<subsystem xmlns="urn:jboss:domain:osgi:1.2" activation="eager"> |
It is also not part of the default configuration. Instead you can use the provided standalone-osgi.xml configuration.
这并不是默认配置的一部分。你可以使用提供的standalone-osgi.xml文件中的配置。
When you start up WildFly you should see something like this
当你启动WildFly的时候你将会看到类似下面的输出:
[tdiesler@localhost wildfly-8.0.0.Alpha3]$ bin/standalone.sh -c standalone-osgi.xml ========================================================================= JBoss Bootstrap Environment JBOSS_HOME: /Users/tdiesler/git/wildfly-8.0.0.Alpha3/build/target/wildfly-8.0.0.Alpha3 JAVA: /Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/bin/java JAVA_OPTS: ... ========================================================================= 12:56:31,829 INFO [org.jboss.modules] (main) JBoss Modules version 1.2.4.Final 12:56:32,081 INFO [org.jboss.msc] (main) JBoss MSC version 1.2.0.Beta1 12:56:32,160 INFO [org.jboss.as] JBAS015899: WildFly 8.0.0.Alpha3 "WildFly" starting ... 12:56:34,741 INFO [org.jboss.osgi.framework] JBOSGI011006: OSGi Framework - 3.0.2.Final 12:56:34,991 INFO [org.jboss.osgi.framework] JBOSGI011001: Bundle installed: org.apache.felix.log:1.0.1 12:56:34,994 INFO [org.jboss.osgi.framework] JBOSGI011001: Bundle installed: jboss-osgi-logging:1.0.0 12:56:34,998 INFO [org.jboss.osgi.framework] JBOSGI011001: Bundle installed: org.apache.felix.configadmin:1.6.0 ... 12:56:35,303 INFO [org.jboss.osgi.framework] JBOSGI011011: Starting bundles for start level: 1 12:56:35,328 INFO [org.jboss.osgi.framework] JBOSGI011002: Bundle started: org.apache.felix.log:1.0.0 12:56:35,342 INFO [org.jboss.osgi.framework] JBOSGI011002: Bundle started: jboss-osgi-logging:1.0.0 12:56:35,377 INFO [org.jboss.osgi.framework] JBOSGI011002: Bundle started: org.apache.felix.configadmin:1.2.8 ... 12:56:35,709 INFO [org.jboss.osgi.framework] JBOSGI011000: OSGi Framework started 12:56:35,769 INFO [org.jboss.as] JBAS015874: WildFly 8.0.0.Alpha2 "WildFly" started in 4379ms 12:46:39,491 INFO [org.jboss.modules] (main) JBoss Modules version 1.2.4.Final 12:46:39,714 INFO [org.jboss.msc] (main) JBoss MSC version 1.2.0.Beta2 ... 12:46:41,417 INFO [org.jboss.osgi.framework] (MSC service thread 1-1) JBOSGI011006: OSGi Framework - 3.0.2.Final 12:46:42,153 INFO [org.jboss.osgi.framework] (MSC service thread 1-3) JBOSGI011001: Bundle installed: org.apache.felix.log:1.0.1 12:46:42,157 INFO [org.jboss.osgi.framework] (MSC service thread 1-3) JBOSGI011001: Bundle installed: jboss-osgi-logging:1.0.0 12:46:42,161 INFO [org.jboss.osgi.framework] (MSC service thread 1-3) JBOSGI011001: Bundle installed: org.apache.felix.configadmin:1.6.0 12:46:42,164 INFO [org.jboss.osgi.framework] (MSC service thread 1-3) JBOSGI011001: Bundle installed: jbosgi-wildfly-configadmin:2.1.0 ... 12:46:42,255 INFO [org.jboss.osgi.framework] (MSC service thread 1-6) JBOSGI011011: Starting bundles for start level: 1 12:46:42,258 INFO [org.jboss.osgi.framework] (MSC service thread 1-6) JBOSGI011002: Bundle started: jbosgi-wildfly-http:2.1.0 12:46:42,258 INFO [org.jboss.osgi.framework] (MSC service thread 1-6) JBOSGI011002: Bundle started: jbosgi-wildfly-jpa:2.1.0 12:46:42,270 INFO [org.jboss.osgi.framework] (MSC service thread 1-6) JBOSGI011002: Bundle started: org.apache.felix.log:1.0.1 12:46:42,283 INFO [org.jboss.osgi.framework] (MSC service thread 1-6) JBOSGI011002: Bundle started: jboss-osgi-logging:1.0.0 12:46:42,308 INFO [org.jboss.osgi.framework] (MSC service thread 1-6) JBOSGI011002: Bundle started: org.apache.felix.configadmin:1.6.0 12:46:42,319 INFO [org.jboss.osgi.framework] (MSC service thread 1-6) JBOSGI011002: Bundle started: jbosgi-wildfly-configadmin:2.1.0 12:46:42,320 INFO [org.jboss.osgi.framework] (MSC service thread 1-6) JBOSGI011000: OSGi Framework started ... 12:46:42,373 INFO [org.jboss.as] (Controller Boot Thread) JBAS015874: WildFly 8.0.0.Alpha3 "WildFly" started in 3197ms |
2.4 提供的示例
The JBoss OSGi project distribution comes with a number of examples that you can build and run in an OSGi standalone environment (i.e. without WildFly integration).
JBoss OSGi发行版由好多示例组成,你可以构建并运行在OSGI单独发行版的环境中(例如没有集成WildFly)。
l blueprint - Basic Blueprint Container examples
l blueprint – 基本的Blueprint容器示例
l configadmin - Configuration Admin example
l Configadmin – 配置管理示例
l core - Simple OSGi examples (start here)
l Core – 在这里启动所有示例
l ds - Declarative Services examples
l Ds – 声明式服务示例
l eventadmin - Event Admin examples
l Eventadmin – 事件管理示例
l jmx - Standard and extended JMX examples
l Jmx – 标准和扩展的JMX示例
Additional to that there are a number of integration examples that document and verify the WildFly Integration
除此之外,还有很多综合的示例:
l cdi - CDI 整合示例
l ear – 企业级架构bundle示例
l ejb3 - EJB3整合示例
l http - HttpService 示例
l interceptor - Intercept and process bundle metadata
l jaxb - XML binding examples
l jaxp - SAX/DOM 解析器示例
l jaxrs - REST 整合示例
l jaxws - WebService 整合示例
l jndi - Naming integration examples
l jpa – 持久化集成示例
l jta – 事务集成示例
l resource – 资源注入示例
l webapp - WebApplication (WAR) 示例
For more information on these examples, see the Provided Examples section.
如果想要了解更多的例子,请参见相关章节。
2.5 Bundle 部署
Bundle Deployment from the command-line is supported through the CLI console and through the web-based Management Console.
Bundle的部署支持从CLI控制台和基于web的管理控制台进行。
It is also possible to deploy bundles by dropping them in the folder.
按照文件夹的方式部署也是可行的。
This will automatically deployments resolve and start the bundle when possible.
当条件满足的时候会自动的部署和启动这个bundle。
Bundles can be started explicitly through the CLI or the web console.
Bundle可以显式的从CLI或者是web控制台启动。
When a bundle is installed and started, messages like the following can be seen from the server console.
当一个bundle被安装和启动后,在控制台中可以看到类似下面的输出:
$ bin/standalone.sh -c standalone-osgi.xml ... 13:53:53,742 INFO [org.jboss.as.server.deployment] JBAS015876: Starting deployment of "org.apache.felix.eventadmin.jar" 13:53:54,196 INFO [org.jboss.osgi.framework] JBOSGI011001: Bundle installed: org.apache.felix.eventadmin:1.3.0 13:53:54,309 INFO [org.jboss.osgi.framework] JBOSGI011002: Bundle started: org.apache.felix.eventadmin:1.3.0 13:53:54,354 INFO [org.jboss.as.server] JBAS018559: Deployed "org.apache.felix.eventadmin.jar" |
2.6 管理已经部署的Bundle
WildFly comes with a Web Console. After startup you can point your browser to http://localhost:9990/console.
WildFly带有web控制台。当启动后你可以访问如下地址:
The Web Console can be used to install, start, stop and uninstall bundles. Additionally, the web console can be used to activate the framework and manage the current framework Start Level.
Web控制台可以用来安装,启动,停止和卸载bundle。除此之外,web控制台还可以用来启动框架和管理当前框架的启动级别。
2.6.1 Felix Web 控制台
For more detailed management operations you can also install the Felix Web Console
如果想要了解更多控制台操作信息,建议你安装Felix Web控制台。
In WildFly 8.x you add this capability
在WildFly 8.x版本中添加如下的配置:
<capability name="org.apache.felix:org.apache.felix.webconsole:3.1.8" startlevel="1"/> |
The console is then accessible on: http://localhost:8080/system/console
下面的地址就可以访问了:http://localhost:8080/system/console