通过使用命令行控制台在运行时调试捆绑软件

OSGi 应用程序命令行控制台是一组 wsadmin 命令,您可以使用这些命令来浏览或调试正在应用程序服务器上运行的一组特定捆绑软件。 作为在测试环境中调试应用程序的一个辅助手段,该控制台还包括用于启动和停止捆绑软件的命令。

有关此任务

可以通过检查 OSGi 框架的内容来探查或调试捆绑软件。 框架包含一个捆绑软件的集合,及与这些捆绑软件关联的软件包和服务。 存在以下两种类型的框架:
隔离的框架
隔离的框架包含专门为特定应用程序定义的捆绑软件;每个 OSGi 应用程序在其自己隔离的框架中运行。 对于在其上安装应用程序的每个服务器,在网络部署环境中有一个隔离的框架。 如果应用程序包括一个或多个组合捆绑软件作为应用程序的一部分或作为应用程序的扩展,那么每个组合捆绑软件都有一个单独的隔离框架。
共享捆绑软件框架
每个服务器都有一个共享的捆绑软件框架,包含可用于安装在服务器上的应用程序的所有共享捆绑软件。 如果应用程序通过软件包依赖性间接引用一个或多个组合捆绑软件,那么每个组合捆绑软件都有一个共享的捆绑软件框架。

要处理当前正在运行的框架,需要先连接到该框架。

过程

  1. 启动 OSGi 应用程序命令行控制台。
    在命令提示符处,运行 osgiApplicationConsole.bat 命令 (对于 Windows 系统) 或 osgiApplicationConsole.sh 命令 (对于 Linux® 系统)。 可以从 app_server_root/bin 目录或从任意的 profile_root/bin 目录运行此命令。 此命令接受以下可选参数:
    -h
    目标机器的主机名。 例如,machine1.hursley.ibm.com
    -o
    目标服务器的 SOAP 端口号。 例如,8880
    -u
    保护 wsadmin 连接时的用户标识。
    -p
    保护 wsadmin 连接时的密码。
    例如:
    app_server_root/bin/osgiApplicationConsole -h machine1.hursley.ibm.com -o 8880
    将显示 wsadmin 命令提示符。 wsadmin 的此实例识别 OSGi 应用程序控制台命令。
  2. 连接到可用框架。

    使用 connect 命令来连接至特定框架。

    如果知道框架名称和版本号以及运行框架的节点和服务器,那么可使用此信息来进行连接。 例如:
    wsadmin>connect("com.ibm.ws.eba.helloWorldService.eba", "1.0.0", "wasNode1", "server1")
    或者,使用 list 命令来列示所有可用的框架并为每个框架提供唯一标识,然后使用此标识来进行连接。 例如:
    1. 列示所有可用的框架:
      wsadmin>list()
      如果正在连接至单个应用程序服务器,那么此命令可能会生成以下系统响应:
      ID   Bundle                                Version  Node      Server
      0    SharedBundles                         7.0.0    wasNode1  server1
      1    com.ibm.ws.eba.helloWorldService.eba  1.0.0    wasNode1  server1
      2    com.ibm.ws.eba.obr.fep.eba5.eba       1.0.0    wasNode1  server1
      3    com.ibm.ws.eba.wab.componenttest      1.0.0    wasNode1  server1
    2. 连接到 com.ibm.ws.eba.helloWorldService.eba 框架:
      wsadmin>connect(1)
      如果命令成功完成,它将生成以下系统响应:
      CWSAJ0035I: Connecting to framework com.ibm.ws.eba.helloWorldService.eba_1.0.0 
      on node wasNode1 and server server1.
      CWSAJ0036I: Successfully connected to framework com.ibm.ws.eba.helloWorldService.eba_1.0.0.

    要连接到其他框架,请再次运行 connect 命令。 连接另一个框架之前,无需断开与前一个框架的连接。

  3. 处理已连接的框架。
    使用以下一个或多个命令来处理您已连接的框架:
    • 列示所有可用的框架并表明当前已连接的框架。
      使用 list 命令:
      wsadmin>list()
      此命令可能会生成以下系统响应:
      ID   Bundle                                Version  Node      Server
      0    SharedBundles                         7.0.0    wasNode1  server1
      1    com.ibm.ws.eba.helloWorldService.eba  1.0.0    wasNode1  server1  <== Connected
      2    com.ibm.ws.eba.obr.fep.eba5.eba       1.0.0    wasNode1  server1
      3    com.ibm.ws.eba.wab.componenttest      1.0.0    wasNode1  server1
    • 显示框架中每个捆绑软件的摘要信息。
      使用 ss 命令:
      wsadmin>ss()
      注: ss 表示 短状态
      此命令可能会生成以下系统响应:
      ID      State       Bundle
      0       ACTIVE      org.eclipse.osgi_3.6.1.R36x_v20100806
      1       ACTIVE      com.ibm.samples.websphere.osgi.blog.app_1.0.0
      2       ACTIVE      com.ibm.samples.websphere.osgi.blog_1.0.0
      3       ACTIVE      com.ibm.samples.websphere.osgi.blog.persistence_1.0.0
      4       ACTIVE      com.ibm.samples.websphere.osgi.blog.web_1.0.0
      5       ACTIVE      com.ibm.samples.websphere.osgi.blog.api_1.0.0
    • 显示有关框架中所有捆绑软件以及它们注册或使用的服务的综合信息。
      使用 bundles 命令:
      wsadmin>bundles()
      此命令可能会生成以下系统响应。
      注: 有关应用程序中包含的捆绑软件的信息列示为捆绑软件 2 和后续捆绑软件。 捆绑软件 0 和 1 为系统工件;不要修改或依赖于这些捆绑软件。 尽管以下示例中并未显示捆绑软件 0 的详细信息,但是此捆绑软件通常会生成比其他捆绑软件更多的信息。
      org.eclipse.osgi_3.6.1.R36x_v20100806 [0]
        Id=0, Status=ACTIVE  Location=System Bundle
      ...
      com.ibm.samples.websphere.osgi.blog.app_1.0.0 [1]
        Id=1, Status=ACTIVE  Location=com.ibm.samples.websphere.osgi.blog.app_1.0.0
      ...
      com.ibm.samples.websphere.osgi.blog_1.0.0 [2]
        Id=2, Status=ACTIVE  
      Location=reference:file:/C:/IBM/WebSphere/AppServer/profiles/profile01/
      installedEBAs/com.ibm.samples.websphere.osgi.blog.app_1.0.0/byValue/
      98b31e7a-4375-45fa-be20-d34b06f5c8b8.3/3/
        Registered Services
      
      {com.ibm.samples.websphere.osgi.blog.api.BloggingService}={service.id=46,
      osgi.service.blueprint.compname=bloggingServiceComponent
      }
      
      {org.osgi.service.blueprint.container.BlueprintContainer}={osgi.blueprint.
      container.symbolicname=com.ibm.samples.websphere.osgi.blog,service.id=47,
      osgi.blueprint.container.version=1.0.0}
        No services in use.
      com.ibm.samples.websphere.osgi.blog.persistence_1.0.0 [3]
        Id=3, Status=ACTIVE  
      Location=reference:file:/C:/IBM/WebSphere/AppServer/profiles/profile01/
      installedEBAs/com.ibm.samples.websphere.osgi.blog.app_1.0.0/byValue/
      98b31e7a-4375-45fa-be20-d34b06f5c8b8.1/1/
        Registered Services
      
      {javax.persistence.EntityManagerFactory}={osgi.unit.provider=org.apache.openjpa.
      persistence.PersistenceProviderImpl,service.id=42,osgi.unit.name=blogExample,
      osgi.unit.version=1.3.0,org.apache.aries.jpa.container.managed=true,org.apache.
      aries.jpa.default.unit.name=false}
      
      {javax.persistence.EntityManagerFactory}={osgi.unit.provider=org.apache.openjpa.
      persistence.PersistenceProviderImpl,service.id=43,org.apache.aries.jpa.proxy.factory=true,
      osgi.unit.name=blogExample,osgi.unit.version=1.3.0,org.apache.aries.jpa.container.managed=true,
      org.apache.aries.jpa.default.unit.name=false}
      
      {com.ibm.samples.websphere.osgi.blog.persistence.api.BlogPersistenceService}={service.id=44,
      osgi.service.blueprint.compname=persistenceImpl}
      
      {org.osgi.service.blueprint.container.BlueprintContainer}={osgi.blueprint.container.
      symbolicname=com.ibm.samples.websphere.osgi.blog.persistence,service.id=45,
      osgi.blueprint.container.version=1.0.0}
        No services in use.
      com.ibm.samples.websphere.osgi.blog.web_1.0.0 [4]
        Id=4, Status=ACTIVE  
      Location=reference:file:/C:/IBM/WebSphere/AppServer/profiles/profile01/
      installedEBAs/com.ibm.samples.websphere.osgi.blog.app_1.0.0/byValue/
      98b31e7a-4375-45fa-be20-d34b06f5c8b8.2/2/
        Registered Services
      
      {javax.servlet.ServletContext}={service.id=48,osgi.web.contextpath=/blog,
      osgi.web.version=1.0.0,osgi.web.symbolicname=com.ibm.samples.websphere.osgi.blog.web}
      
      {org.osgi.service.blueprint.container.BlueprintContainer}={osgi.blueprint.container.
      symbolicname=com.ibm.samples.websphere.osgi.blog.web,service.id=49,
      osgi.blueprint.container.version=1.0.0}
        No services in use.
      com.ibm.samples.websphere.osgi.blog.api_1.0.0 [5]
        Id=5, Status=ACTIVE  
      Location=reference:file:/C:/IBM/WebSphere/AppServer/profiles/profile01/
      installedEBAs/com.ibm.samples.websphere.osgi.blog.app_1.0.0/byValue/
      98b31e7a-4375-45fa-be20-d34b06f5c8b8.0/0/
        No registered services.
        No services in use.
    • 显示框架中有关给定捆绑软件的完整信息。

      使用 bundle 命令。 指定要检查的捆绑软件的标识。 捆绑软件标识值是 ss 命令的其中一个输出。

      此命令列示与指定的捆绑软件相关联的信息。 例如,捆绑软件符号名称、捆绑软件版本、捆绑软件注册的服务、捆绑软件使用的服务以及捆绑软件是片段捆绑软件还是主捆绑软件。

      例如:
      wsadmin>bundle(3)
      此命令可能会生成以下系统响应:
      com.ibm.samples.websphere.osgi.blog.persistence_1.0.0 [3]
        Id=3, Status=ACTIVE  
      Location=reference:file:/C:/IBM/WebSphere/AppServer/profiles/profile01/
      installedEBAs/com.ibm.samples.websphere.osgi.blog.app_1.0.0/byValue/
      98b31e7a-4375-45fa-be20-d34b06f5c8b8.1/1/
        Registered Services
      
      {javax.persistence.EntityManagerFactory}={osgi.unit.provider=org.apache.openjpa.
      persistence.PersistenceProviderImpl,service.id=42,osgi.unit.name=blogExample,
      osgi.unit.version=1.3.0,org.apache.aries.jpa.container.managed=true,org.apache.
      aries.jpa.default.unit.name=false}
      
      {javax.persistence.EntityManagerFactory}={osgi.unit.provider=org.apache.openjpa.
      persistence.PersistenceProviderImpl,service.id=43,org.apache.aries.jpa.proxy.factory=true,
      osgi.unit.name=blogExample,osgi.unit.version=1.3.0,org.apache.aries.jpa.container.managed=true,
      org.apache.aries.jpa.default.unit.name=false}
      
      {com.ibm.samples.websphere.osgi.blog.persistence.api.BlogPersistenceService}={service.id=44,
      osgi.service.blueprint.compname=persistenceImpl}
      
      {org.osgi.service.blueprint.container.BlueprintContainer}={osgi.blueprint.container.
      symbolicname=com.ibm.samples.websphere.osgi.blog.persistence,service.id=45,
      osgi.blueprint.container.version=1.0.0}
        No services in use.
        No exported packages
        Imported Packages
        Imported Packages
          com.ibm.samples.websphere.osgi.blog.persistence.api; 
          version="1.0.0"<com.ibm.samples.websphere.osgi.blog.api_1.0.0 [3]>
          javax.persistence; version="1.1.0"<org.eclipse.osgi_3.6.1.R36x_v20100806 [3]>
        No fragment bundles
        No host bundles
        No named class spaces
        Required bundles
          org.eclipse.osgi_3.6.1.R36x_v20100806 [0]
          com.ibm.samples.websphere.osgi.blog.api_1.0.0 [5]
    • 显示有关给定捆绑软件的头信息。

      使用 headers 命令。 指定要检查的捆绑软件的标识。 捆绑软件标识值是 ss 命令的其中一个输出。

      例如:
      wsadmin>headers(2)
      此命令可能会生成以下系统响应:
      Ant-Version = Apache Ant 1.7.1
      Bundle-ActivationPolicy = lazy
      Bundle-ManifestVersion = 2
      Bundle-Name = Blog Core Services Bundle
      Bundle-SymbolicName = com.ibm.samples.websphere.osgi.blog
      Bundle-Vendor = IBM
      Bundle-Version = 1.0.0
      Created-By = 2.4 (Your Corporation)
      Import-Package = com.ibm.samples.websphere.osgi.logging;version="[1.0.0,1.1.0)",
      com.ibm.samples.websphere.osgi.blog.api;version="[1.0.0,1.1.0)",
      com.ibm.samples.websphere.osgi.blog.comment.persistence.api;version="[1.0.0,1.1.0)",
      com.ibm.samples.websphere.osgi.blog.persistence.api;version="[1.0.0,1.1.0)"
      Manifest-Version = 1.0
    • 显示由框架导入或导出的软件包的相关信息。
      使用 packages 命令。 可以指定以下一个或两个参数以选择特定的软件包或软件包子集:
      bundle ID
      显示有关此捆绑软件导出软件包的信息。
      捆绑软件标识值是 ss 命令的其中一个输出。
      package name
      显示有关指定的软件包的信息。
      命令语法:
      wsadmin>packages()
      wsadmin>packages(bundle_id)
      wsadmin>packages(package_name)
      使用捆绑软件标识的示例:
      wsadmin>packages(5)
      此命令可能会生成以下系统响应:
      com.ibm.samples.websphere.osgi.blog.persistence.api; version="1.0.0"
      <com.ibm.samples.websphere.osgi.blog.api_1.0.0 [5]>
        com.ibm.samples.websphere.osgi.blog_1.0.0 [2] imports
        com.ibm.samples.websphere.osgi.blog.persistence_1.0.0 [3] imports 
      com.ibm.samples.websphere.osgi.blog.comment.persistence.api; version="1.0.0"
      <com.ibm.samples.websphere.osgi.blog.api_1.0.0 [5]>
        com.ibm.samples.websphere.osgi.blog_1.0.0 [2] imports 
      com.ibm.samples.websphere.osgi.blog.api; version="1.0.0"
      <com.ibm.samples.websphere.osgi.blog.api_1.0.0 [5]>
        com.ibm.samples.websphere.osgi.blog_1.0.0 [2] imports
        com.ibm.samples.websphere.osgi.blog.web_1.0.0 [4] imports
      使用软件包名称的示例:
      wsadmin>packages("com.ibm.samples.websphere.osgi.blog.comment.persistence.api")
      此命令可能会生成以下系统响应:
      com.ibm.samples.websphere.osgi.blog.comment.persistence.api; version="1.0.0"
      <com.ibm.samples.websphere.osgi.blog.api_1.0.0 [5]>
        com.ibm.samples.websphere.osgi.blog_1.0.0 [2] imports
    • 显示当前由框架注册的服务的相关信息。 对于每个服务,此信息包括服务接口、注册该服务的捆绑软件以及使用该服务的任何捆绑软件。
      使用 services 命令。 可以指定以下一个或两个参数以选择特定的服务或服务子集:
      service ID
      显示有关指定服务的信息。
      filter
      显示与过滤器相匹配的所有服务的相关信息。
      过滤器必须符合在 OSGi Service Platform R4 V4.2 核心规范的第 3.2.6 节中定义的 OSGi 过滤器格式。
      命令语法:
      wsadmin>services()
      wsadmin>services(service_id)
      wsadmin>services("(&(prop1=value_1)(prop2=value_2))")
      使用服务标识的示例:
      wsadmin>services(2)
      此命令可能会生成以下系统响应:
      {org.osgi.service.packageadmin.PackageAdmin}={service.id=2,
      service.ranking=2147483647,service.vendor=Eclipse.org - Equinox,
      service.pid=0.org.eclipse.osgi.framework.internal.core.PackageAdminImpl}
        Registered by bundle: org.eclipse.osgi_3.6.1.R36x_v20100806 [0]
        Bundles using service:
          org.eclipse.osgi_3.6.1.R36x_v20100806 [0]
      使用单一属性过滤器的示例:
      wsadmin>services("(objectClass=org.osgi.service.packageadmin.PackageAdmin)")
      此命令可能会生成以下系统响应:
      {org.osgi.service.packageadmin.PackageAdmin}={service.id=2,
      service.ranking=2147483647,service.vendor=Eclipse.org - Equinox,
      service.pid=0.org.eclipse.osgi.framework.internal.core.PackageAdminImpl}
        Registered by bundle: org.eclipse.osgi_3.6.1.R36x_v20100806 [0]
        Bundles using service:
          org.eclipse.osgi_3.6.1.R36x_v20100806 [0]
      使用多个属性过滤器的示例:
      wsadmin>services("(&(objectClass=javax.resource.Referenceable)(ibm.private.jndi.object=true))")
      此命令可能会生成以下系统响应:
      {java.lang.reflect.InvocationHandler,com.ibm.websphere.rsadapter.WSDataSource,java.sql.Wrapper,
      javax.sql.CommonDataSource,javax.resource.Referenceable,javax.sql.DataSource}={service.id=35,
      osgi.jndi.service.name=jdbc/pgc,ibm.private.jndi.object=true}
        Registered by bundle: org.eclipse.osgi_3.6.1.R36x_v20100806 [0]
        No bundles using service.
      {java.lang.reflect.InvocationHandler,com.ibm.websphere.rsadapter.WSDataSource,java.sql.Wrapper,
      javax.sql.CommonDataSource,javax.resource.Referenceable,javax.sql.DataSource}={service.id=36,
      osgi.jndi.service.name=jdbc/DefaultEJBTimerDataSource,ibm.private.jndi.object=true}
        Registered by bundle: org.eclipse.osgi_3.6.1.R36x_v20100806 [0]
        No bundles using service.
      {java.lang.reflect.InvocationHandler,com.ibm.websphere.rsadapter.WSDataSource,java.sql.Wrapper,
      javax.sql.CommonDataSource,javax.resource.Referenceable,javax.sql.DataSource}={service.id=39,
      osgi.jndi.service.name=jdbc/lrsched,ibm.private.jndi.object=true}
        Registered by bundle: org.eclipse.osgi_3.6.1.R36x_v20100806 [0]
        No bundles using service.
      {javax.resource.Referenceable,javax.resource.cci.ConnectionFactory}={service.id=40,
      osgi.jndi.service.name=eis/jdbc/pgc_CMP,ibm.private.jndi.object=true}
        Registered by bundle: org.eclipse.osgi_3.6.1.R36x_v20100806 [0]
        No bundles using service.
    • 更新有关框架的高速缓存运行时信息。
      系统可能要花费一些时间来收集有关框架以及在框架中运行的捆绑软件的运行时信息。 因此,运行 osgiApplicationConsole 命令时,命令行控制台可能会对运行时信息进行高速缓存。 如果更改了当前选择的框架(例如,通过更新或添加捆绑软件),那么在运行 refresh 命令之前,这些更改不会反映在命令行控制台命令的输出中。
      注: 您还可以通过重新启动 OSGi 应用程序命令行控制台来更新此运行时信息。 但是,随后您必须重新连接至该框架。 使用 refresh 命令速度会更快。
      命令语法:
      wsadmin>refresh()
    • 停止捆绑软件。

      使用 stop 命令来停止给定捆绑软件标识指定的捆绑软件。 捆绑软件标识值是 ss 命令的其中一个输出。

      注:
      • OSGi 应用程序命令行控制台主要用于对应用程序进行调试。 在生产环境中,通常使用管理控制台或同等的管理命令来启动和停止应用程序。
      • 请勿在共享捆绑软件框架下的任何捆绑软件上,系统捆绑软件上或表示系统工件 (捆绑软件标识 0 和 1) 的捆绑软件上使用 stop 命令,否则会导致严重错误。
      例如:
      wsadmin>stop(5)
      此命令可能会生成以下系统响应:
      CWSAJ0042I: Stopping Bundle com.ibm.samples.websphere.osgi.blog.api_1.0.0.
      CWSAJ0034I: Bundle com.ibm.samples.websphere.osgi.blog.api stopped successfully.
    • 启动捆绑软件。

      使用 start 命令来启动由给定捆绑软件标识指定的捆绑软件。 捆绑软件标识值是 ss 命令的其中一个输出。

      注:
      • OSGi 应用程序命令行控制台主要用于对应用程序进行调试。 在生产环境中,通常使用管理控制台或同等的管理命令来启动和停止应用程序。
      • 请勿对共享捆绑软件框架下的任何捆绑软件,系统捆绑软件或表示应用程序的捆绑软件 (捆绑软件标识 0 和 1) 使用 start 命令,否则会导致严重错误。
      例如:
      wsadmin>start(5)
      此命令可能会生成以下系统响应:
      CWSAJ0040I: Starting Bundle com.ibm.samples.websphere.osgi.blog.api_1.0.0.
      CWSAJ0032I: Bundle com.ibm.samples.websphere.osgi.blog.api started successfully.
    • 显示有关控制台命令的帮助信息。

      使用 help 命令来显示运行时命令及其用法的摘要。

      命令语法:
      wsadmin>help()
      此命令生成以下系统响应:
      CWSAJ0025I:      OSGi application console
      
      Display commands: These commands work only if connected to a framework
      
      ss()                - This command gives the summary information about the installed bundles.
      bundles()           - This command gives comprehensive information about the installed bundles.
      packages()          - This command gives information about the imported/exported packages.
      services()          - This command gives information about the registered Services.
      
      bundle(<bundleID>)  - This command gives information about the specified bundle
      headers(<bundleID>) - This command gives information about the headers associated with the 
                            specified bundle
      packages(<bundle ID>) - This command gives information about the exported packages for this bundle.
      packages(<package Name>) - This command gives information about the specified package.
      services(<service ID>) - This command gives information about the specified service.
      services(<OSGI Filter>) - This command gives information about the services matching the filter.
      
      refresh() - This command refreshes the internal OSGi application console cache with the latest 
                  information about the state of the framework.
      
      Framework commands:
      
      list() - This command lists the available frameworks that you can connect to.
      connect(<Framework id>) - This command connects to the specified framework.
      connect(<Bundle Name>, <Bundle Version>, <Node Name>, <Server Name>)
                       - This command connects to the specified framework.
      
      Controlling Bundles:
      
      start(<bundleID>) - This command starts the requested bundle.
      stop(<bundleID>   - This command stops the requested bundle.