Arun Gupta, Miles to go ...

Arun Gupta is a technology enthusiast, a passionate runner, and a community guy who works for Sun Microsystems.

http://blogs.sun.com/arungupta/date/20090915 Tuesday September 15, 2009

TOTD #103: GlassFish v3 with different OSGi runtimes – Felix, Equinox, and Knoplerfish

GlassFish v3 uses standard OSGi APIs to achieve modularity. It bundles Apache Felix 2.0 as the OSGi runtime and can run on any other OSGi R4.1 compliant runtimes as well. This blog will use previously described instructions and show how to run GlassFish v3 on Eclipse Equinox and Knoplerfish. The complete details about different OSGi runtimes is described here, this TOTD provide detailed steps and overrides the instructions defined here (and here and here).

This blog is using a CI build from last week but you should try the instructions on a promoted build.

GlassFish with Felix - Felix 2.0.0 is bundled with GlassFish v3 and requires no additional configurations.

  1. Start GlassFish as:
    ~/tools/glassfish/v3/2269/glassfishv3/glassfish >./bin/asadmin start-domain --verbose
    

    and see the following messages in the log:
    Sep 11, 2009 4:41:16 PM com.sun.enterprise.glassfish.bootstrap.ASMain main
    INFO: Launching GlassFish on Felix platform
    
    Welcome to Felix
    ================
    
    . . .
    
    Sep 11, 2009 4:41:30 PM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: GlassFish v3  startup time : Felix(9669ms) startup services(4453ms) total(14122ms)
    
    
  2. Optionally, connect to Felix runtime using Apache Felix Remote Shell (described here) as:

    ~/tools/glassfish/v3/2269/glassfishv3 >telnet localhost 6666
    Trying ::1...
    telnet: connect to address ::1: Connection refused
    Trying fe80::1...
    telnet: connect to address fe80::1: Connection refused
    Trying 127.0.0.1...
    Connected to localhost.
    Escape character is '^]'.
    
    Felix Remote Shell Console:
    ============================
    
    ->
    


    and type "help" to see the list of commands available as:

    -> help
    bundlelevel
    cd
    find
    headers
    help
    inspect
    install
    log
    ps
    refresh
    resolve
    shutdown
    start
    startlevel
    stop
    uninstall
    update
    version
    
    Use 'help ' for more information.
    
  3. See the list of OSGi modules installed as:
    -> ps
    START LEVEL 1
       ID   State         Level  Name
    [   0] [Active     ] [    0] System Bundle (2.0.0)
    [   1] [Active     ] [    1] HK2 OSGi Main Bundle (0.3.91)
    [   2] [Installed  ] [    1] EclipseLink Core (2.0.0.v20090821-r4934)
    [   3] [Resolved   ] [    1] Hibernate validator library and Validation API (JSR 303) repackaged as OSGi and HK2 bundle (3.0.0.JBoss-400Beta3)
    [   4] [Installed  ] [    1] Connector (gluecode) for GlassFish Java EE Connector Architecture Runtime (3.0.0.SNAPSHOT)
    [   5] [Active     ] [    1] GlassFish Flashlight Framework (3.0.0.SNAPSHOT)
    
    . . .
    
    [ 201] [Resolved   ] [    1] glassfish-corba-asm (3.0.0.b024)
    [ 202] [Resolved   ] [    1] MIME streaming extension (1.4)
    [ 203] [Installed  ] [    1] Admin Console Connectors Plugin (3.0.0.SNAPSHOT)
    [ 204] [Installed  ] [    1] Apache Felix Shell TUI (1.4.0)
    [ 205] [Resolved   ] [    1] org.glassfish.core.glassfish-extra-jre-packages
    
  4. Use "headers" command to display the bundle header properties for any bundle. "help <command>" shows more information about each command displayed in the output of "help". Finally type "exit" to quit the shell.

GlassFish on Equinox

  1. Download Equinox latest release from http://www.eclipse.org/equinox/ (3.5 as of this writing).
  2. Unzip the contents and copy the Equinox jar file to "osgi/equinox" directory of GlassFish as shown below:
    ~/tools/glassfish/v3/2269/glassfishv3/glassfish >unzip ~/Downloads/equinox-SDK-3.5.zip -d ~/tools/equinox-3.5
    ~/tools/glassfish/v3/2269/glassfishv3/glassfish >cp ~/tools/equinox-3.5/plugins/org.eclipse.osgi_3.5.0.v20090520.jar ./osgi/equinox
    
    
  3. Start GlassFish as:
    ~/tools/glassfish/v3/2269/glassfishv3 >GlassFish_Platform=Equinox ./bin/asadmin start-domain --verbose
    

    and see the following messages in the log:
    Sep 11, 2009 5:11:13 PM com.sun.enterprise.glassfish.bootstrap.ASMain main
    INFO: Launching GlassFish on Equinox platform
    Listening on port 6667 ...
    
    . . .
    
    Sep 11, 2009 5:11:19 PM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: GlassFish v3  startup time : Equinox(3649ms) startup services(1843ms) total(5492ms)
    


    Note, Equinox platform started on port 6667 for remote management.
  4. Optionally, connect to Equinox runtime as:

    ~/tools/glassfish/v3/2269/glassfishv3/glassfish >telnet localhost 6667
    Trying ::1...
    Connected to localhost.
    Escape character is '^]'.
    
    osgi>
    
    

    Make sure to use the port number specified during the startup. Type "help" to see the list of commands available as:
    osgi> help
    ---Controlling the OSGi framework---
            launch - start the OSGi Framework
            shutdown - shutdown the OSGi Framework
            close - shutdown and exit
            exit - exit immediately (System.exit)
            init - uninstall all bundles
            setprop = - set the OSGi property
    ---Controlling Bundles---
    
    . . . 
    
    ---Controlling the Console---
            more - More prompt for console output
            disconnect - Disconnects from telnet session
    
  5. See the list of OSGi modules installed as:
    osgi> ss
    
    Framework is launched.
    
    id      State       Bundle
    0       ACTIVE      org.eclipse.osgi_3.5.0.v20090520
                        Fragments=62, 128, 205
    1       ACTIVE      com.sun.enterprise.osgi-main_0.3.91
    2       RESOLVED    org.eclipse.persistence.core_2.0.0.v20090821-r4934
                        Fragments=136
    
    . . . 
    
    203     RESOLVED    org.glassfish.admingui.console-jca-plugin_3.0.0.SNAPSHOT
    204     RESOLVED    org.apache.felix.shell.tui_1.4.0
    205     RESOLVED    org.glassfish.core.glassfish-extra-jre-packages_0.0.0
                        Master=0
    

    Typing "help" shows a comprehensive list of commands. Finally type "disconnect" to terminate the shell. Do not type "exit" as it terminates the Equinox shell and killing the GlassFish process as well.

GlassFish with Knoplerfish - As mentioned here, GlassFish v3 requires at least R4.1 APIs. All Knopflerfish releases prior to 3.0.0 are R4 compliant and so will not work with the GlassFish v3 latest builds. Knopflerfish 3.0.0 beta1 is the first build that is R4.2 compliant but it does not start on Mac OS X 10.5.8 as described in issue #2858798. So until then, you you can follow the instructions documented at  GlassFish v3 on OSGi KnopflerFish and Using KnopflerFish Desktop in GlassFish v3 to get them running on GlassFish v3 TP2 or Prelude.

Some additional details missing form the entries above

  1. Download Knoplerfish 2.3.3 and install.
  2. In "knopflerfish_osgi_2.3.3/knopflerfish.org/osgi", copy "props.xargs" to "gf.xargs" and add the lines mentioned here. Make sure to copy the Knopflerfish related files to the modules directory and change the location accordingly.
  3. Create "gfpackages.txt" by copying "felix/conf/config.properties" from the GlassFish directory. List each package specified in the "gf-packages" property on a single line. There should be no other character such as ";" or "," or "/" on a line, only the package name.
  4. Start GlassFish as:
    ~/tools/glassfish/v3/2269/glassfishv3/glassfish >KNOPFLERFISH_HOME=/Users/arungupta/tools/knopflerfish_osgi_2.3.3/knopflerfish.org/osgi GlassFish_Platform=Knopflerfish ./bin/asadmin start-domain --verbose
    
    
    and see the following messages in the log:
    Knopflerfish OSGi framework, version 4.1.10
    Copyright 2003-2009 Knopflerfish. All Rights Reserved.
    
    See http://www.knopflerfish.org for more information.
    Loading xargs url file:/Users/arungupta/tools/knopflerfish_osgi_2.3.3/knopflerfish.org/osgi/gf.xargs
    Removed existing fwdir /Users/arungupta/tools/knopflerfish_osgi_2.3.3/knopflerfish.org/osgi/fwdir
    Installed: file:/Users/arungupta/tools/glassfish/v3/glassfishv3-tp2/glassfish/modules/tiger-types-osgi-0.2.1.jar (id#1)
    Installed: file:/Users/arungupta/tools/glassfish/v3/glassfishv3-tp2/glassfish/modules/auto-depends-0.2.1.jar (id#2)
    Installed: file:/Users/arungupta/tools/glassfish/v3/glassfishv3-tp2/glassfish/modules/config-0.2.1.jar (id#3)
    
    . . .
    
    Started: file:/Users/arungupta/tools/glassfish/v3/glassfishv3-tp2/glassfish/modules/cm_all-2.0.1.jar (id#7)
    Started: file:/Users/arungupta/tools/glassfish/v3/glassfishv3-tp2/glassfish/modules/console_all-2.0.1.jar (id#8)
    Started: file:/Users/arungupta/tools/glassfish/v3/glassfishv3-tp2/glassfish/modules/desktop_all-2.3.11.jar (id#11)
    


    and finally see the Knopflerfish console as:



The instructions will be updated after a more stable release of Knopflerfish is available.

A complete archive of all the tips is available here.

Technorati: totd glassfish v3 osgi apache felix eclipse equinox knopflerfish

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20080626 Thursday June 26, 2008

TOTD #36: Deploy OSGi bundles in GlassFish using maven-bundle-plugin


GlassFish v3 is a modular (OSGi compliant), embeddable (runs in-VM) and extensible (supports non-Java apps) Application Server.

The extensible part is demonstrated by deployment of Rails and Grails applications. An example of embeddability is an in-VM Servlet. This blog demonstrates how a simple OSGi bundle can be easily created using Maven Bundle Plugin and deployed on v3 trunk.

  1. Generate a simple Maven project using the command as shown below:

    ~/samples/v3 >mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=org.glassfish.samples.osgi.helloworld -DartifactId=helloworld
    [INFO] Scanning for projects...
    [INFO] Searching repository for plugin with prefix: 'archetype'.
    [INFO] Ignoring available plugin update: 2.0-alpha-3 as it requires Maven version 2.0.7
    [INFO] Ignoring available plugin update: 2.0-alpha-2 as it requires Maven version 2.0.7
    [INFO] Ignoring available plugin update: 2.0-alpha-1 as it requires Maven version 2.0.7
    [INFO] ----------------------------------------------------------------------------
    [INFO] Building Maven Default Project
    [INFO]    task-segment: [archetype:create] (aggregator-style)
    [INFO] ----------------------------------------------------------------------------
    [INFO] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'.
    [INFO] Setting property: velocimacro.messages.on => 'false'.
    [INFO] Setting property: resource.loader => 'classpath'.
    [INFO] Setting property: resource.manager.logwhenfound => 'false'.
    [INFO] **************************************************************
    [INFO] Starting Jakarta Velocity v1.4
    [INFO] RuntimeInstance initializing.
    [INFO] Default Properties File: org/apache/velocity/runtime/defaults/velocity.properties
    [INFO] Default ResourceManager initializing. (class org.apache.velocity.runtime.resource.ResourceManagerImpl)
    [INFO] Resource Loader Instantiated: org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader
    [INFO] ClasspathResourceLoader : initialization starting.
    [INFO] ClasspathResourceLoader : initialization complete.
    [INFO] ResourceCache : initialized. (class org.apache.velocity.runtime.resource.ResourceCacheImpl)
    [INFO] Default ResourceManager initialization complete.
    [INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Literal
    [INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Macro
    [INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Parse
    [INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Include
    [INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Foreach
    [INFO] Created: 20 parsers.
    [INFO] Velocimacro : initialization starting.
    [INFO] Velocimacro : adding VMs from VM library template : VM_global_library.vm
    [ERROR] ResourceManager : unable to find resource 'VM_global_library.vm' in any resource loader.
    [INFO] Velocimacro : error using  VM library template VM_global_library.vm : org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'VM_global_library.vm'
    [INFO] Velocimacro :  VM library template macro registration complete.
    [INFO] Velocimacro : allowInline = true : VMs can be defined inline in templates
    [INFO] Velocimacro : allowInlineToOverride = false : VMs defined inline may NOT replace previous VM definitions
    [INFO] Velocimacro : allowInlineLocal = false : VMs defined inline will be  global in scope if allowed.
    [INFO] Velocimacro : initialization complete.
    [INFO] Velocity successfully started.
    [INFO] [archetype:create]
    [INFO] Defaulting package to group ID: org.glassfish.samples.osgi.helloworld
    [INFO] ----------------------------------------------------------------------------
    [INFO] Using following parameters for creating Archetype: maven-archetype-quickstart:RELEASE
    [INFO] ----------------------------------------------------------------------------
    [INFO] Parameter: groupId, Value: org.glassfish.samples.osgi.helloworld
    [INFO] Parameter: packageName, Value: org.glassfish.samples.osgi.helloworld
    [INFO] Parameter: basedir, Value: /Users/arungupta/samples/v3
    [INFO] Parameter: package, Value: org.glassfish.samples.osgi.helloworld
    [INFO] Parameter: version, Value: 1.0-SNAPSHOT
    [INFO] Parameter: artifactId, Value: helloworld
    [INFO] ********************* End of debug info from resources from generated POM ***********************
    [INFO] Archetype created in dir: /Users/arungupta/samples/v3/helloworld
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESSFUL
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 1 second
    [INFO] Finished at: Wed Jun 25 10:07:27 PDT 2008
    [INFO] Final Memory: 5M/10M
    [INFO] ------------------------------------------------------------------------
  2. Change the generated App class in "src/main/java/org/glassfish/samples/osgi/helloworld" folder so that it looks like:

    package org.glassfish.samples.osgi.helloworld;

    import org.osgi.framework.BundleActivator;
    import org.osgi.framework.BundleContext;

    /**
     * Hello world!
     *
     */
    public class App implements BundleActivator {
        public void start(BundleContext context) throws Exception {
            System.out.println("Hey!");
        }
        public void stop(BundleContext context) throws Exception {
            System.out.println("Bye!");
        }
    }


    This is a trivial Activator class but sitll shows the key methods. The changes are highlighted in bold.
  3. Update "pom.xml" with the following changes:
    1. Change the <packaging> to "bundle" from the default value of "jar".
    2. Add the <dependency> on "org.osgi.core".
    3. Add the <plugin> maven-bundle-plugin and provide <instructions> to generate the appropriate MANIFEST.MF.

    The updated "pom.xml" with changes highlighted in bold are shown below:

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>org.glassfish.samples.osgi.helloworld</groupId>
      <artifactId>helloworld</artifactId>
      <packaging>bundle</packaging>
      <version>1.0-SNAPSHOT</version>
      <name>helloworld</name>
      <url>http://maven.apache.org</url>
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
          <scope>test</scope>
        </dependency>
        <dependency>
          <groupId>org.apache.felix</groupId>
          <artifactId>org.osgi.core</artifactId>
          <version>1.0.0</version>
        </dependency>
      </dependencies>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <extensions>true</extensions>
            <configuration>
              <instructions>
                <Export-Package>${pom.groupId}</Export-Package>
                <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
                <Bundle-Activator>${pom.groupId}.App</Bundle-Activator>
              </instructions>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </project>
  4. Generate the OSGi bundle as shown below:

    ~/samples/v3/helloworld >mvn install
    [INFO] Scanning for projects...
    [INFO] ----------------------------------------------------------------------------
    [INFO] Building helloworld
    [INFO]    task-segment: [install]
    [INFO] ----------------------------------------------------------------------------
    [INFO] [resources:resources]
    [INFO] Using default encoding to copy filtered resources.
    [INFO] [compiler:compile]
    [INFO] Compiling 1 source file to /Users/arungupta/samples/v3/helloworld/target/classes
    [INFO] [resources:testResources]
    [INFO] Using default encoding to copy filtered resources.
    [INFO] [compiler:testCompile]
    [INFO] Compiling 1 source file to /Users/arungupta/samples/v3/helloworld/target/test-classes
    [INFO] [surefire:test]
    [INFO] Surefire report directory: /Users/arungupta/samples/v3/helloworld/target/surefire-reports

    -------------------------------------------------------
     T E S T S
    -------------------------------------------------------
    Running org.glassfish.samples.osgi.helloworld.AppTest
    Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.022 sec

    Results :

    Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

    [INFO] [bundle:bundle]
    [INFO] [install:install]
    [INFO] Installing /Users/arungupta/samples/v3/helloworld/target/helloworld-1.0-SNAPSHOT.jar to /Users/arungupta/.m2/repository/org/glassfish/samples/osgi/helloworld/helloworld/1.0-SNAPSHOT/helloworld-1.0-SNAPSHOT.jar
    [INFO] [bundle:install]
    [INFO] Parsing file:/Users/arungupta/.m2/repository/repository.xml
    [INFO] Installing org/glassfish/samples/osgi/helloworld/helloworld/1.0-SNAPSHOT/helloworld-1.0-SNAPSHOT.jar
    [INFO] Writing OBR metadata
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESSFUL
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 4 seconds
    [INFO] Finished at: Wed Jun 25 10:20:27 PDT 2008
    [INFO] Final Memory: 22M/54M
    [INFO] ------------------------------------------------------------------------

    The generated "target/helloworld-1.0-SNAPSHOT.jar" has the following contents:

    META-INF/MANIFEST.MF
    META-INF/
    META-INF/maven/
    META-INF/maven/org.glassfish.samples.osgi.helloworld/
    META-INF/maven/org.glassfish.samples.osgi.helloworld/helloworld/
    META-INF/maven/org.glassfish.samples.osgi.helloworld/helloworld/pom.properties
    META-INF/maven/org.glassfish.samples.osgi.helloworld/helloworld/pom.xml
    org/
    org/glassfish/
    org/glassfish/samples/
    org/glassfish/samples/osgi/
    org/glassfish/samples/osgi/helloworld/
    org/glassfish/samples/osgi/helloworld/App.class

    And the generated "MANIFEST.MF" looks like:

    Manifest-Version: 1.0
    Export-Package: org.glassfish.samples.osgi.helloworld;uses:="org.osgi.
     framework"
    Built-By: arungupta
    Tool: Bnd-0.0.255
    Bundle-Name: helloworld
    Created-By: Apache Maven Bundle Plugin
    Bundle-Version: 1.0.0.SNAPSHOT
    Build-Jdk: 1.6.0_05
    Bnd-LastModified: 1214414426851
    Bundle-ManifestVersion: 2
    Bundle-Activator: org.glassfish.samples.osgi.helloworld.App
    Import-Package: org.glassfish.samples.osgi.helloworld,org.osgi.framewo
     rk;version="1.3"
    Bundle-SymbolicName: helloworld
Now let's install this newly created bundle using Felix shell in GlassFish v3. Check out and build GlassFish v3 workspace as explained in TOTD #33. Unzip "~/workspaces/glassfish/v3/distributions/web/target/web.zip" and enable Felix TUI as explained in TOTD #34.
  1. Start GlassFish v3 as:

    ~/testbed/glassfish/v3/snapshot/glassfish >java -jar modules/glassfish-10.0-SNAPSHOT.jar
    Jun 25, 2008 4:09:19 PM com.sun.enterprise.glassfish.bootstrap.ASMain main
    INFO: Launching GlassFish on Apache Felix OSGi platform
    Jun 25, 2008 4:09:19 PM com.sun.enterprise.glassfish.bootstrap.ASMainOSGi getSharedRepos
    INFO: /Users/arungupta/testbed/glassfish/v3/snapshot/glassfish/domains/domain1/lib does not exist

    Welcome to Felix.
    =================

    Jun 25, 2008 4:09:20 PM HK2Main start
    INFO: contextRootDir = /Users/arungupta/testbed/glassfish/v3/snapshot/glassfish/modules
    Jun 25, 2008 4:09:20 PM OSGiFactoryImpl initialize
    INFO: Singleton already initialized as com.sun.enterprise.module.impl.HK2Factory@3d44d0c6
    Jun 25, 2008 4:09:20 PM OSGiModuleImpl loadClass
    INFO: Started bundle org.glassfish.common.glassfish-mbeanserver [19]
    Jun 25, 2008 4:09:20 PM OSGiModuleImpl loadClass
    INFO: Started bundle org.glassfish.core.kernel [51]
    Jun 25, 2008 4:09:21 PM OSGiModuleImpl loadClass
    INFO: Started bundle org.glassfish.common.glassfish-naming [8]
    Jun 25, 2008 4:09:21 PM OSGiModuleImpl loadClass
    INFO: Started bundle org.glassfish.admin.config-api [43]
    Jun 25, 2008 4:09:21 PM OSGiModuleImpl loadClass
    INFO: Started bundle org.glassfish.common.internal-api [33]
    Jun 25, 2008 4:09:21 PM OSGiModuleImpl loadClass
    INFO: Started bundle org.glassfish.deployment.deployment-common [10]
    Jun 25, 2008 4:09:21 PM 
    INFO: JMXMP connector server URL = service:jmx:jmxmp://localhost:8888
    Jun 25, 2008 4:09:21 PM com.sun.enterprise.v3.services.impl.GrizzlyProxy start
    INFO: Listening on port 8080
    Jun 25, 2008 4:09:21 PM com.sun.enterprise.v3.services.impl.GrizzlyProxy start
    INFO: Listening on port 8181
    Jun 25, 2008 4:09:21 PM com.sun.enterprise.v3.services.impl.GrizzlyProxy start
    INFO: Listening on port 4848
    Jun 25, 2008 4:09:21 PM OSGiModuleImpl loadClass
    INFO: Started bundle org.glassfish.common.container-common [21]
    Jun 25, 2008 4:09:22 PM com.sun.enterprise.v3.admin.adapter.AdminConsoleAdapter setContextRoot
    INFO: Admin Console Adapter: context root: /admin
    Jun 25, 2008 4:09:22 PM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: Glassfish v3 started in 1789 ms
    Jun 25, 2008 4:09:22 PM 
    INFO: ->
    Jun 25, 2008 4:09:22 PM com.sun.enterprise.glassfish.bootstrap.ASMainFelix launchOSGiFW
    INFO: Framework successfully started
  2. Install the Hello World bundle as:

    install file:///Users/arungupta/samples/v3/helloworld/target/helloworld-1.0-SNAPSHOT.jar
    Jun 25, 2008 4:10:19 PM 
    INFO: Bundle ID: 75
    Jun 25, 2008 4:10:19 PM 
    INFO: ->

    The command output shows "75" as the process id. This id is used to start/stop/uninstall the bundle later.
  3. Check the bundle status

    ps     
    Jun 25, 2008 4:10:27 PM 
    INFO: START LEVEL 1
    Jun 25, 2008 4:10:27 PM 
    INFO:    ID   State         Level  Name
    Jun 25, 2008 4:10:27 PM 
    INFO: [   0] [Active     ] [    0] System Bundle (1.0.4)
    Jun 25, 2008 4:10:27 PM 
    INFO: [   1] [Active     ] [    1] org.jvnet.tiger-types repackaged as module (0.3.2)
    Jun 25, 2008 4:10:27 PM 

    . . .

    INFO: [  71] [Installed  ] [    1] Web module command line interface (10.0.0.SNAPSHOT)
    Jun 25, 2008 4:10:27 PM 
    INFO: [  72] [Installed  ] [    1] Admin GUI Web Container Plugin (10.0.0.SNAPSHOT)
    Jun 25, 2008 4:10:27 PM 
    INFO: [  75] [Installed  ] [    1] helloworld (1.0.0.SNAPSHOT)
    Jun 25, 2008 4:10:27 PM 
    INFO: ->

    The last log output shows the newly added process.
  4. Start the bundle as:

    start 75
    Jun 25, 2008 4:10:32 PM 
    INFO: Hey!
    Jun 25, 2008 4:10:32 PM 
    INFO: ->

    This fragment shows "Hey!" output printed from the start method of Activator.
  5. Stop the bundle as:

    stop 75
    Jun 25, 2008 4:10:35 PM 
    INFO: Bye!
    Jun 25, 2008 4:10:35 PM 
    INFO: ->

    This fragment shows "Bye!" output printed from the stop method of Activator.
  6. And finally uninstall the bundle as:

    uninstall 75
    Jun 25, 2008 4:10:42 PM 
    INFO: ->
So following this blog you can deploy any of your OSGi bundles in GlassFish v3.

Technorati: glassfish v3 osgi maven mavenbundleplugin

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20080620 Friday June 20, 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

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20080616 Monday June 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

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

Valid HTML! Valid CSS!

This is a personal weblog, I do not speak for my employer.