2
votes

I want to upgrade from JSF implementation Mojarra 2.1.3 in Netbeans7.1 (Glassfish 3.1.1).

You might ask first why I don't just upgrade to Netbeans7.3, and the reasons include that it it runs Glassfish 3.1.2.2 and that I have some other 3rd party software in my web application that is not yet compatible with Glassfish higher than 3.1.1, and besides it only has Mojarra 2.1.6 anyway.

I used to be able to upgrade Mojarra by simply replacing jsf-api.jar and jsf-impl.jar under /glassfish/modules, but that does not work with:

https://maven.java.net/content/repositories/releases/com/sun/faces/jsf-api/2.1.21/jsf-api-2.1.21.jar https://maven.java.net/content/repositories/releases/com/sun/faces/jsf-impl/2.1.21/jsf-impl-2.1.21.jar

I get the following error:

    SEVERE: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.enterprise.glassfish.bootstrap.GlassFishMain.main(GlassFishMain.java:97)
at com.sun.enterprise.glassfish.bootstrap.ASMain.main(ASMain.java:55)
Caused by: com.sun.enterprise.module.ResolveError: Failed to start Bundle Id [301] State [INSTALLED] [org.glassfish.web.weld-integration(Weld integration for glassfish):3.1.1]
at org.jvnet.hk2.osgiadapter.OSGiModuleImpl.start(OSGiModuleImpl.java:177)
at org.jvnet.hk2.osgiadapter.OSGiModuleImpl$2$1$1.loadClass(OSGiModuleImpl.java:344)
at com.sun.hk2.component.LazyInhabitant.loadClass(LazyInhabitant.java:124)
at com.sun.hk2.component.LazyInhabitant.fetch(LazyInhabitant.java:111)
at com.sun.hk2.component.EventPublishingInhabitant.get(EventPublishingInhabitant.java:135)
at com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl.java:76)
at org.jvnet.hk2.component.Habitat$5.get(Habitat.java:701)
at java.util.AbstractList$Itr.next(AbstractList.java:345)
at java.util.AbstractCollection.toArray(AbstractCollection.java:124)
at java.util.ArrayList.addAll(ArrayList.java:472)
at com.sun.enterprise.v3.server.SnifferManagerImpl.getSniffers(SnifferManagerImpl.java:92)
at com.sun.enterprise.v3.server.SnifferManagerImpl.getSniffer(SnifferManagerImpl.java:120)
at com.sun.enterprise.v3.server.ApplicationLifecycle.getSniffersFromApp(ApplicationLifecycle.java:2140)
at com.sun.enterprise.v3.server.ApplicationLoaderService.processApplication(ApplicationLoaderService.java:375)
at com.sun.enterprise.v3.server.ApplicationLoaderService.postConstruct(ApplicationLoaderService.java:219)
at com.sun.hk2.component.AbstractCreatorImpl.inject(AbstractCreatorImpl.java:131)
at com.sun.hk2.component.ConstructorCreator.initialize(ConstructorCreator.java:91)
at com.sun.hk2.component.AbstractCreatorImpl.get(AbstractCreatorImpl.java:82)
at com.sun.hk2.component.SingletonInhabitant.get(SingletonInhabitant.java:67)
at com.sun.hk2.component.EventPublishingInhabitant.get(EventPublishingInhabitant.java:139)
at com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl.java:76)
at com.sun.enterprise.v3.server.AppServerStartup.run(AppServerStartup.java:253)
at com.sun.enterprise.v3.server.AppServerStartup.doStart(AppServerStartup.java:145)
at com.sun.enterprise.v3.server.AppServerStartup.start(AppServerStartup.java:136)
at com.sun.enterprise.glassfish.bootstrap.GlassFishImpl.start(GlassFishImpl.java:79)
at com.sun.enterprise.glassfish.bootstrap.GlassFishDecorator.start(GlassFishDecorator.java:63)
at com.sun.enterprise.glassfish.bootstrap.osgi.OSGiGlassFishImpl.start(OSGiGlassFishImpl.java:69)
at com.sun.enterprise.glassfish.bootstrap.GlassFishMain$Launcher.launch(GlassFishMain.java:117)
... 6 more
Caused by: org.osgi.framework.BundleException: Unresolved constraint in bundle org.glassfish.web.weld-integration [301]: Unable to resolve 301.0: missing requirement [301.0] package; (&(package=com.sun.faces.spi)(version>=2.1.0)) [caused by: Unable to resolve 213.1: missing requirement [213.1] package; (package=javax.faces) [caused by: Unable to resolve 211.1: missing requirement [211.1] package; (&(package=javax.el)(version>=2.2.1))]]
at org.apache.felix.framework.Felix.resolveBundle(Felix.java:3443)
at org.apache.felix.framework.Felix.startBundle(Felix.java:1727)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:922)
at org.jvnet.hk2.osgiadapter.OSGiModuleImpl.start(OSGiModuleImpl.java:169)

I tried web app specific JSF but that also fails:

glassfish change default jsf impl

Added to web.xml:

<class-loader delegate="false" />
<property name="useBundledJsf" value="true" />

I get the error:

Error occurred during deployment: Exception while loading the app :    
java.lang.IllegalStateException: ContainerBase.addChild: start:  
org.apache.catalina.LifecycleException: java.lang.RuntimeException: 
com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! 
org.glassfish.weld.jsf.WeldFacesConfigProvider cannot be cast to 
com.sun.faces.spi.ConfigurationResourceProvider. Please see server.log for more details.

Grateful for suggestions.

2
And I tried deleting everything in the glassfish/domains/domain1/osgi-cache before glassfish restart after replacing jsf-impl.jar and jsf-api.jar. What has changed in Mojarra upgrade technique, and where is reference/documentation for the new upgrade requirements ?Webel IT Australia - upvoter
I just found this from BalusC: stackoverflow.com/questions/12792222/… "Just replace both jsf-api.jar and jsf-impl.jar in the Glassfish /modules folder by the single javax.faces.jar file. Since Mojarra 2.1.6 the build system has been changed to comply Java EE Maven rules, see also issue 2028. This resulted in the API and impl being merged into a single JAR file. java.net/jira/browse/JAVASERVERFACES-2028"Webel IT Australia - upvoter
I did as BalusC suggested, replace both jsf-api.jar and jsf-impl.jar with javax.faces.jar, but Netbeans stubbornly refuses to see it, javax.faces.jar will not appear under the Glassfish server libs (in Netbeans7.1). I have deleted the osgi-cache, I have even deleted the .netbeans/7.1/var/cache, but Netbeans will not see it. I get errors with imports like import javax.faces.bean.ManagedBean.Webel IT Australia - upvoter
I tried removing/adding the server in NetBeans7.1, it did not help. I had deleted both osgi-cache and NetBeans ~/.netbeans/7.1/var/cache (on Mac OS X). NetBeans7.1 stubbornly refuses to show javax.faces.jar under the Glassfish server libs and I still get import errors.Webel IT Australia - upvoter
Also, after replacing jsf-api.jar and jsf-impl.jar with javax.faces.jar, Netbeans7.1 will no longer show Frameworks for a project, it hangs. I have never used the Mac OS X "Force quit" feature so often. I just can't get NetBeans7.1 to see javax.faces.jar.Webel IT Australia - upvoter

2 Answers

2
votes

Try following steps

  • Download jsf 2.1.21 jar from here
  • Rename it to javax.faces.jar .
  • Take backup of javax.faces.jar available at docroot\glassfish\modules
  • Paste and replace the old javax.faces.jar with downloaded javax.faces.jar available at docroot\glassfish\modules
  • Delete the osgi cache glassfish3\glassfish\osgi for the changes to take effect
2
votes

OK I finally have 2 workarounds (only) for getting Mojarra-2.1.21 running with Netbeans7.1.

Firstly, the following recommended approach does not as far as I can tell work in Netbeans7.1, it stubbornly refuses to recognise the server installed javax.faces.jar.

From https://weblogs.java.net/blog/edburns/archive/2011/09/26/try-out-mojarra-220-snapshot?force=714:

Once you download the javax.faces.jar, you must take some steps to install it in GlassFish 3.1 or 3.1.1.

Remove jsf-api.jar and jsf-impl.jar from the modules directory.

Put javax.faces.jar in the modules directory.

You must modify the default-web.xml file in domains/domain1/config and lib/templates. In each directory, remove any mention of jsf-api.jar and jsf-impl.jar from the default.web.xml file. In place of the two jars, add a reference to javax.faces.jar.

No matter what I do with Netbeans7.1 (and no matter whether clear osgi-cache and netbeans cache or whether remove then re-add server in Netbeans7.1 or how many times I restart glassfish3.1.1 and/or netbeans7.1), Netbeans7.1 will NOT see javax.faces.jar.

If you try to add the javax.faces.jar (only) to your web app libs and use this in glassfish-web.xml to for it to use web-app specific JSF, it will prevent import errors in your Netbeans7.1 project, but it still will not run:

<class-loader delegate="false" />
<property name="useBundledJsf" value="true" />

I get this error:

Error occurred during deployment: Exception while loading the app :   
java.lang.IllegalStateException: ContainerBase.addChild: start:   
org.apache.catalina.LifecycleException: java.lang.RuntimeException:   
com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED!   
org.glassfish.weld.jsf.WeldFacesConfigProvider cannot be cast to 
com.sun.faces.spi.ConfigurationResourceProvider.

The reason is described here: http://java.dzone.com/articles/upgrading-latest-mojarra

The issue seems to be that there are two versions of ConfigurationResourceProvider on the class path: one at the web app level (your bundled jar file) and a second at the parent class loader level (provided by GlassFish). WeldFacesConfigProvider extends ConfigurationResourceProvider at the parent class loader, but it ends up casting this to ConfigurationResourceProvider at the web app class loader. ... Workaround: Adding the missing dependency to your app If you can't cast across class loaders you have to make the missing part available to the right class-loader. Not replacing the javax.faces.jar in your server's modules leads to adding the magic WeldFacesConfigProvider to your app. It is contained in the glassfish3\glassfish\modules\weld-integration.jar and by simply putting that as an additional library to your application you also solve the issue.

You now have 2 workaround choices:

  1. Include the weld-integration.jar in your web app libs, and run with web app JSF settings in glassfish-web.xml.

  2. Dirty trick: With .../glassfish/modules/javax.faces.jar still in place and also in your web app libs, disable or uncomment the bit in your glassfish-web.xml. It will then run with the server javax.faces.jar (and will see /modules/weld-integration.jar), and Netbeans will see the web app specific lib for imports.

This is unsatisfactory, I don't consider the question fully answered.

Q: How can one run JSF Mojarra 2.1.21 as Glassfish3.1.1 server JSF libs in NetBeans7.1 ?

And again, the reason I can't just upgrade Netbeans+Glassfish is that I have multiple problems with ObjectDB with versions of Glassfish above 3.1.1, which is why I am so adamant about installing JSF Mojarra 2.1.21 on Netbeans7.1+Glassfish3.1.1.

Grateful for any further suggestions.