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.
Post a Comment
Note: Only a member of this blog may post a comment.