d8888 888 888      88888888888 888      d8b                                 888       888          888       .d8888b.           888                               
      d88888 888 888          888     888      Y8P                                 888   o   888          888      d88P  Y88b          888                               
     d88P888 888 888          888     888                                          888  d8b  888          888      Y88b.               888                               
    d88P 888 888 888          888     88888b.  888 88888b.   .d88b.  .d8888b       888 d888b 888  .d88b.  88888b.   "Y888b.   88888b.  88888b.   .d88b.  888d888 .d88b.  
   d88P  888 888 888          888     888 "88b 888 888 "88b d88P"88b 88K           888d88888b888 d8P  Y8b 888 "88b     "Y88b. 888 "88b 888 "88b d8P  Y8b 888P"  d8P  Y8b 
  d88P   888 888 888          888     888  888 888 888  888 888  888 "Y8888b.      88888P Y88888 88888888 888  888       "888 888  888 888  888 88888888 888    88888888 
 d8888888888 888 888          888     888  888 888 888  888 Y88b 888      X88      8888P   Y8888 Y8b.     888 d88P Y88b  d88P 888 d88P 888  888 Y8b.     888    Y8b.     
d88P     888 888 888          888     888  888 888 888  888  "Y88888  88888P'      888P     Y888  "Y8888  88888P"   "Y8888P"  88888P"  888  888  "Y8888  888     "Y8888  
                                                                 888                                                          888                                        
                                                            Y8b d88P                                                          888                                        
                                                             "Y88P"                                                           888   

All Things WebSphere

Concerns and issues relating to all versions of WebSphere Application Server

Thursday, November 3, 2011

 

How to get Contexts & Dependency Injection (JSR 299) running on WebSphere Application Server 7.0.0.x

Please understand that even with these changes you are losing a lot of WAS value-add and integration of Dependency Integration with Java EE resources in WAS i.e. pojo injection in a servlet/EJB or vice versa. IBM cannot help with support calls on WAS 7 when open web beans or JSF 2 is bundled as part of the application.  For dependency injection in WAS we recommend upgrading to WAS 8 which has CDI and JSF2 support baked in.

1. OpenWebBeans (OWB) Download
Register for JIRA and watch OpenWebBeans project here https://issues.apache.org/jira/browse/OWB
Versions https://issues.apache.org/jira/browse/OWB#selectedTab=com.atlassian.jira.plugin.system.project%3Aversions-panel
Latest version     1.1.2    Release Date: 21/Oct/11    OpenWebBeans-1.1.2
Distribution: https://repository.apache.org/content/repositories/releases/org/apache/openwebbeans/openwebbeans-distribution/1.1.2/
Download and unzip https://repository.apache.org/content/repositories/releases/org/apache/openwebbeans/openwebbeans-distribution/1.1.2/openwebbeans-distribution-1.1.2-binary.tar.gz
to C:\WebSphere7\AppServer\temp where C:\WebSphere7\AppServer is my WAS_INSTALL_ROOT
C:\WebSphere7\AppServer\temp was chosen as an arbitrary location for download. You can do this in any directory.
After unzip you should see C:\WebSphere7\AppServer\temp\openwebbeans-distribution-1.1.2

2.  Build a sample that comes with the OWB Distribution
In this scenario I will be building the jsf2sample application.
This examples shows the usage of MyFaces JSF2 + OpenWebBeans .
Before building the application add org.apache.myfaces.webapp.StartupServletContextListener
to the web.xml of your application if you intend to use JSF2.0. This is how the listener stanza should look like

    <listener>
        <listener-class>org.apache.webbeans.servlet.WebBeansConfigurationListener</listener-class>
        <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
    </listener>

For this to work you will need to add
<profiles>
    <profile>
      <id>apache</id>
      <pluginRepositories>
        <pluginRepository>
          <id>apache.snapshots</id>
          <name>Maven Plugin Snapshots</name>
          <url>http://repository.apache.org/snapshots/</url>
          <releases>
            <enabled>false</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>

  <activeProfiles>
    <activeProfile>apache</activeProfile>
  </activeProfiles>

to your global settings in M2_INSTALL_HOME\conf\settings.xml or  user settings from M2_USER_HOME\.m2\settings.xml . To determine these settings locations type "mvn -X"

You may need to change the pom.xml of the sample application
Replace ../pom.xml in with
https://repository.apache.org/content/repositories/releases/org/apache/openwebbeans/openwebbeans/1.1.2/openwebbeans-1.1.2.pom/pom.xml
You may also need to delete myfaces.version xml element from   org.apache.myfaces.core ...
After building the jsf2sample  CDI you should see C:\WebSphere7\AppServer\temp\openwebbeans-distribution-1.1.2\samples\jsf2sample\target\jsf2sample.war

3.  Configure WAS 7 to use JSF 2.0

Because WAS 7 comes with its own implementation of JSF we have to follow the steps below for the jsf2sample to leverage JSF 2.0 myfaces correctly.

3.1 Extract
commons-beanutils-1.8.3.jar,
commons-codec-1.3.jar,
commons-collections-3.2.jar,
commons-digester-1.8.jar,
commons-logging-1.1.1.jar,
myfaces-api-2.0.3.jar,
myfaces-impl-2.0.3.jar from the WEB-INF/lib dir of the application to a common place on your server where you want to store them.
    Say  ${WAS_INSTALL_ROOT}\optionalLibraries\Apache\MyFaces..

3.2 Delete the 7 jar files listed above from the WEB-INF/lib dir of the app
3.3 Open up the myfaces-impl-2.0.x.jar file and remove the files in the META-INF\services\ directory.
3.4 Install js2sample.war  application on WAS 7

3.5 Configuring WAS v7 shared libraries
Next, we configure the JAR files as Isolated Shared libraries.

Add the following to Environment > Shared Libraries > New

Name
OWB

Classpath
${WAS_INSTALL_ROOT}/optionalLibraries/IBM/JSFProviders/WebSphere-MyFaces20-annotation-provider.jar  (this is needed and only available on & after 7.0.0.19)
${WAS_INSTALL_ROOT}/optionalLibraries/Apache/owb/commons-beanutils-1.8.3.jar
${WAS_INSTALL_ROOT}/optionalLibraries/Apache/owb/commons-codec-1.3.jar
${WAS_INSTALL_ROOT}/optionalLibraries/Apache/owb/commons-collections-3.2.jar
${WAS_INSTALL_ROOT}/optionalLibraries/Apache/owb/commons-digester-1.8.jar
${WAS_INSTALL_ROOT}/optionalLibraries/Apache/owb/commons-logging-1.1.1.jar
${WAS_INSTALL_ROOT}/optionalLibraries/Apache/owb/myfaces-api-2.0.3.jar
${WAS_INSTALL_ROOT}/optionalLibraries/Apache/owb/myfaces-impl-2.0.3.jar

Click on the check box for ‘Use an isolated class loader for this shared library’. Click Apply and Save.

3.6 Associate the shared library with your
Go to Enterprise Applications > jsf2sample_war > Shared library references and add the OWB shared library reference
to both web module

3.7 If you want at this point you can enable trace for *=info:org.apache.webbeans*=all to get more information about the OWB
and WAS interaction

3.8 Restart the application server

4. Confirmation
After the server has started look for these messages to validate that your CDI application has started
[11/2/11 15:53:57:141 EDT] 00000008 WebContainerL 2 org.apache.webbeans.web.lifecycle.WebContainerLifecycle debug Deploying scanned beans.
[11/2/11 15:53:57:250 EDT] 00000008 BeansDeployer 2 org.apache.webbeans.config.BeansDeployer debug Found Managed Bean with class name : [org.apache.webbeans.jsf2.HelloJsfBean]
[11/2/11 15:53:57:391 EDT] 00000008 WebContainerL I org.apache.webbeans.web.lifecycle.WebContainerLifecycle info OpenWebBeans Container has started, it took [313] ms.
[11/2/11 15:53:59:860 EDT] 00000008 servlet       I com.ibm.ws.webcontainer.servlet.ServletWrapper init SRVE0242I: [jsf2sample_war] [/jsf2sample] [Faces Servlet]: Initialization successful.

5. Final Validation

Hit
   - http://localhost:9081/jsf2sample/counter.xhtml
     Shows the AJAX functionality of JSF2 specification.

   - http://localhost:9081/jsf2sample/conversation.xhtml
     Show the usage of JSF conversations.

where 9081 is the WC_defaulthost port.

Labels:


Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Subscribe to Post Comments [Atom]





<< Home

Archives

December 2006   September 2008   January 2009   February 2009   March 2009   September 2009   October 2009   November 2009   December 2009   January 2010   February 2010   March 2010   April 2010   October 2010   January 2011   February 2011   April 2011   May 2011   June 2011   July 2011   August 2011   September 2011   October 2011   November 2011   December 2011   January 2012   February 2012   March 2012   April 2012   May 2012   June 2012   July 2012   August 2012   September 2012   October 2012   November 2012   January 2013   May 2013   June 2013   July 2013   September 2013   October 2013   June 2014   August 2014  

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]