Thursday Jun 19, 2008

TOTD #34: Using Felix Shell with GlassFish

TOTD #33 explains how to create a GlassFish v3 distribution that uses Apache Felix (default) as the  OSGi R4 Service Platform runtime. This blog explains how to use Felix Shell TUI with that bundle to issue commands to the OSGi framework and obtain information from it.

To enable Felix Shell with GlassFish v3, add the lines ...

 ${com.sun.aas.installRootURI}/felix/bundle/org.apache.felix.shell.jar \\
 ${com.sun.aas.installRootURI}/felix/bundle/org.apache.felix.shell.tui.jar

to "felix.auto.start.1" property in "felix/conf/config.properties" file of the expanded bundle. The updated property looks like:

felix.auto.start.1= \\
 ${com.sun.aas.installRootURI}/modules/tiger-types-osgi-0.3.2.jar \\
 ${com.sun.aas.installRootURI}/modules/auto-depends-0.3.2.jar \\
 ${com.sun.aas.installRootURI}/modules/config-0.3.2.jar \\
 ${com.sun.aas.installRootURI}/modules/hk2-core-0.3.2.jar \\
 ${com.sun.aas.installRootURI}/modules/osgi-adapter-0.3.2.jar \\
 ${com.sun.aas.installRootURI}/felix/bundle/org.apache.felix.shell.jar \\
 ${com.sun.aas.installRootURI}/felix/bundle/org.apache.felix.shell.tui.jar

with the changes highlighted in bold.

The shell works only if GlassFish is started using "java -jar modules/glassfish-10.0-SNAPSHOT.jar" command.

The shell is available when the following prompt is shown:

INFO: Glassfish v3 started in 1624 ms
Jun 16, 2008 7:10:37 PM  
INFO: ->
Jun 16, 2008 7:10:37 PM com.sun.enterprise.glassfish.bootstrap.ASMainFelix launchOSGiFW
INFO: Framework successfully started

You can type "help" in the shell to see the complete list of commands that are available:

help
Jun 16, 2008 7:11:12 PM  
INFO: bundlelevel <level> <id> ... | <id> - set or get bundle start level.
Jun 16, 2008 7:11:12 PM  
INFO: cd [<base-URL>]                     - change or display base URL.
Jun 16, 2008 7:11:12 PM  
INFO: headers [<id> ...]                  - display bundle header properties.
Jun 16, 2008 7:11:12 PM  
INFO: help                                - display impl commands.
Jun 16, 2008 7:11:12 PM  
INFO: install <URL> [<URL> ...]           - install bundle(s).
Jun 16, 2008 7:11:12 PM  
INFO: packages [<id> ...]                 - list exported packages.
Jun 16, 2008 7:11:12 PM  
INFO: ps [-l | -s | -u]                   - list installed bundles.
Jun 16, 2008 7:11:12 PM  
INFO: refresh [<id> ...]                  - refresh packages.
Jun 16, 2008 7:11:12 PM  
INFO: resolve [<id> ...]                  - attempt to resolve the specified bundles.
Jun 16, 2008 7:11:12 PM  
INFO: services [-u] [-a] [<id> ...]       - list registered or used services.
Jun 16, 2008 7:11:12 PM  
INFO: shutdown                            - shutdown framework.
Jun 16, 2008 7:11:12 PM  
INFO: start <id> [<id> <URL> ...]         - start bundle(s).
Jun 16, 2008 7:11:12 PM  
INFO: startlevel [<level>]                - get or set framework start level.
Jun 16, 2008 7:11:12 PM  
INFO: stop <id> [<id> ...]                - stop bundle(s).
Jun 16, 2008 7:11:12 PM  
INFO: uninstall <id> [<id> ...]           - uninstall bundle(s).
Jun 16, 2008 7:11:12 PM  
INFO: update <id> [<URL>]                 - update bundle.
Jun 16, 2008 7:11:12 PM  
INFO: version                             - display version of framework.
Jun 16, 2008 7:11:12 PM  
INFO: -> 

This shows the list of available commands along with a brief description. For example "ps" shows the list of installed bundles as shown below:

ps
Jun 16, 2008 7:13:57 PM  
INFO: START LEVEL 1
Jun 16, 2008 7:13:57 PM  
INFO:    ID   State         Level  Name
Jun 16, 2008 7:13:57 PM  
INFO: [   0] [Active     ] [    0] System Bundle (1.0.4)
Jun 16, 2008 7:13:57 PM  
INFO: [   1] [Active     ] [    1] org.jvnet.tiger-types repackaged as module (0.3.2)
. . .
INFO: [ 137] [Installed  ] [    1] WebTier Security Integration (10.0.0.SNAPSHOT)
Jun 16, 2008 7:13:57 PM 
INFO: [ 138] [Installed  ] [    1] Web module command line interface (10.0.0.SNAPSHOT)
Jun 16, 2008 7:13:57 PM 
INFO: [ 139] [Installed  ] [    1] Admin GUI Web Container Plugin (10.0.0.SNAPSHOT)
Jun 16, 2008 7:13:57 PM 
INFO: ->

More details about the commands and options are available @ Felix Usage Docs.

The commands are described in "felix/conf/config.properties" (around line 38).

Please leave suggestions on other TOTD (Tip Of The Day) that you'd like to see. A complete archive is available here.

Technorati: totd glassfish v3 felix osgi

Monday Jun 16, 2008

TOTD #33: Building GlassFish v3 Workspace

Reviving after a 2-week hiatus ...

This TOTD (Tip Of The Day) provides complete instructions on how to checkout/build GlassFish v3 workspace.
  1. Check out the workspace as ...

    ~/workspaces/glassfish >svn checkout https://svn.dev.java.net/svn/glassfish-svn/trunk/v3
    Error validating server certificate for 'https://svn.dev.java.net:443':
     - The certificate is not issued by a trusted authority. Use the
       fingerprint to validate the certificate manually!
    Certificate information:
     - Hostname: \*.dev.java.net
     - Valid: from Thu, 09 Aug 2007 06:44:32 GMT until Sat, 09 Aug 2008 06:44:32 GMT
     - Issuer: Equifax Secure Inc., US
     - Fingerprint: e9:12:f6:a0:36:fe:7d:b0:07:dd:8b:d6:c3:b6:29:ff:ba:02:03:46
    (R)eject, accept (t)emporarily or accept (p)ermanently? t
    Authentication realm: <https://svn.dev.java.net:443> CollabNet Subversion Repository
    Password for 'arungupta':  <YOUR PASSWORD HERE>
    A    v3/deployment
    A    v3/deployment/javaee-core
    A    v3/deployment/javaee-core/src
    A    v3/deployment/javaee-core/src/main
    . . .
    A    v3/packager/packages/glassfishv3-ejb/build.properties
    A    v3/packager/packages/glassfishv3-ejb/build.xml
    A    v3/packager/packages/glassfishv3-ejb/glassfishv3-ejb.spec.tmpl
    A    v3/packager/packages/README
     U   v3
    Checked out revision 21054.

  2. The directory structure looks like:

    ~/workspaces/glassfish/v3 >ls -la
    total 24
    drwxr-xr-x  25 arungupta  arungupta    850 Jun 16 15:03 .
    drwxr-xr-x   3 arungupta  arungupta    102 Jun 16 14:58 ..
    drwxr-xr-x  10 arungupta  arungupta    340 Jun 16 15:03 .svn
    drwxr-xr-x  17 arungupta  arungupta    578 Jun 16 15:00 admin
    drwxr-xr-x  10 arungupta  arungupta    340 Jun 16 15:01 admingui
    drwxr-xr-x   6 arungupta  arungupta    204 Jun 16 15:01 build
    drwxr-xr-x  15 arungupta  arungupta    510 Jun 16 15:00 common
    drwxr-xr-x   9 arungupta  arungupta    306 Jun 16 15:03 connectors
    drwxr-xr-x   7 arungupta  arungupta    238 Jun 16 14:59 core
    drwxr-xr-x  10 arungupta  arungupta    340 Jun 16 14:58 deployment
    drwxr-xr-x  10 arungupta  arungupta    340 Jun 16 15:01 distributions
    drwxr-xr-x   9 arungupta  arungupta    306 Jun 16 15:01 ejb
    drwxr-xr-x   8 arungupta  arungupta    272 Jun 16 15:02 extras
    drwxr-xr-x   6 arungupta  arungupta    204 Jun 16 15:00 installer
    drwxr-xr-x  27 arungupta  arungupta    918 Jun 16 15:01 javaee-api
    drwxr-xr-x   5 arungupta  arungupta    170 Jun 16 15:02 osgi-platforms
    drwxr-xr-x  13 arungupta  arungupta    442 Jun 16 15:03 packager
    drwxr-xr-x   6 arungupta  arungupta    204 Jun 16 14:58 persistence
    -rw-r--r--   1 arungupta  arungupta  11866 Jun 16 15:03 pom.xml
    drwxr-xr-x   6 arungupta  arungupta    204 Jun 16 15:02 registration
    drwxr-xr-x   7 arungupta  arungupta    238 Jun 16 15:02 security
    drwxr-xr-x   8 arungupta  arungupta    272 Jun 16 15:01 tests
    drwxr-xr-x   8 arungupta  arungupta    272 Jun 16 14:58 transaction
    drwxr-xr-x  15 arungupta  arungupta    510 Jun 16 15:02 web
    drwxr-xr-x   5 arungupta  arungupta    170 Jun 16 14:58 webservices
  3. Set the Maven options as ...

    export MAVEN_OPTS=-Xmx512m

    And build the distribution as ...

    ~/workspaces/glassfish/v3 >mvn -U install
    [INFO] Scanning for projects...
    [INFO] Reactor build order:
    [INFO]   GlassFish Build Utilities
    [INFO]   GlassFish v3 Maven2 plugin
    [INFO]   Maven extension for building GlassFish
    [INFO]   GlassFish Parent Project
    . . .
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESSFUL
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 5 minutes 56 seconds
    [INFO] Finished at: Mon Jun 16 15:33:46 PDT 2008
    [INFO] Final Memory: 57M/121M
    [INFO] ------------------------------------------------------------------------

    You need to use "mvn -U clean install" for a previously built workspace.
  4. Unzip the created distribution as:

    ~/testbed/glassfish/v3/snapshot >unzip ~/workspaces/glassfish/v3/distributions/glassfish/target/glassfish-10.0-SNAPSHOT.zip
    Archive:  /Users/arungupta/workspaces/glassfish/v3/distributions/glassfish/target/glassfish-10.0-SNAPSHOT.zip
       creating: glassfish/
       creating: glassfish/docs/
    . . .
      inflating: glassfish/lib/templates/keyfile 
      inflating: glassfish/lib/templates/logging.properties 
      inflating: glassfish/lib/templates/login.conf 
      inflating: glassfish/lib/templates/profile.properties 
      inflating: glassfish/lib/templates/server.policy

    The unzipped distribution directory looks like:

    ~/testbed/glassfish/v3/snapshot/glassfish >ls -la
    total 592
    drwxr-xr-x  14 arungupta  arungupta     476 Apr 23 16:37 .
    drwxr-xr-x   3 arungupta  arungupta     102 Jun 16 15:40 ..
    -rw-r--r--   1 arungupta  arungupta  250464 Jun 16 15:24 3RD-PARTY-LICENSE.txt
    -rw-r--r--   1 arungupta  arungupta    4603 Jun 16 15:24 COPYRIGHT
    -rw-r--r--   1 arungupta  arungupta   36116 Jun 16 15:24 LICENSE.txt
    -rw-r--r--   1 arungupta  arungupta     271 Jun 16 15:24 README
    drwxr-xr-x   8 arungupta  arungupta     272 Jun 16 15:33 bin
    drwxr-xr-x   6 arungupta  arungupta     204 Jun 16 15:33 config
    drwxr-xr-x   7 arungupta  arungupta     238 Jun 16 15:33 docs
    drwxr-xr-x   3 arungupta  arungupta     102 Jun 16 15:33 domains
    drwxr-xr-x   5 arungupta  arungupta     170 Jun 16 15:33 felix
    drwxr-xr-x   9 arungupta  arungupta     306 Jun 16 15:32 javadb
    drwxr-xr-x  11 arungupta  arungupta     374 Apr 23 16:37 lib
    drwxr-xr-x  74 arungupta  arungupta    2516 Jun 16 15:33 modules

    Start GlassFish as ...

    ~/testbed/glassfish/v3/snapshot/glassfish >bin/asadmin start-domain -v
    Jun 16, 2008 3:44:54 PM com.sun.enterprise.admin.launcher.GFLauncherLogger info
    INFO: JVM invocation command line:
    /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/bin/java
    -cp
    /Users/arungupta/testbed/glassfish/v3/snapshot/glassfish/modules/glassfish-10.0-SNAPSHOT.jar
    -XX:+UnlockDiagnosticVMOptions
    -XX:NewRatio=2
    . . .
    INFO: Started bundle org.glassfish.common.container-common [85]
    Jun 16, 2008 3:44:56 PM com.sun.enterprise.v3.admin.adapter.AdminConsoleAdapter setContextRoot
    INFO: Admin Console Adapter: context root: /admin
    Jun 16, 2008 3:44:56 PM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: Glassfish v3 started in 1594 ms
    Jun 16, 2008 3:44:56 PM com.sun.enterprise.glassfish.bootstrap.ASMainFelix launchOSGiFW
    INFO: Framework successfully started

And you'll see the default page as shown below:



Hurrah!

This starts GlassFish v3 using Apache Felix as the OSGi platform. Alternatively, you can start GlassFish using the command "java -jar modules/glassfish-10.0-SNAPSHOT.jar". The complete instructions are available on GlassFish Wiki.

Please leave suggestions on other TOTD (Tip Of The Day) that you'd like to see. A complete archive is available here.

Technorati: totd glassfish v3 felix osgi
About

profile image
Arun Gupta is a technology enthusiast, a passionate runner, author, and a community guy who works for Oracle Corp.


Java EE 7 Samples

Stay Connected

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today