title: How to use alternate version of Mojarra with Glassfish 4 (Netbeans/Maven)
body: <p>I've been Using Eclipse/Ant for some time and decided to take a look at Netbeans/Maven for my JSF development.  Along the way, I thought I'd try to use a version of Mojarra that is newer than the one I have installed in <code>glassfish/modules</code>.  I can't seem to get that to work, and since I'm new to both Maven and Netbeans, I'm not sure if it's something with those, or something else.</p>
  
  <p>I've made a very simple app which uses a backing bean to print out the Mojarra version from the index page:</p>
  
  <p><strong>Info.java</strong>:</p>
  
  <pre><code>@Named
  @RequestScoped
  public class Info
  {
    public String getVersion()
    {
      return FacesContext.class.getPackage().getImplementationVersion();
    }
  }
  </code></pre>
  
  <p><strong>index.xhtml</strong>:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://xmlns.jcp.org/jsf/html"&gt;
    &lt;h:body&gt;
      &lt;h:outputText value="The Mojarra version is #{info.version}" /&gt;
    &lt;/h:body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>When I run this, I see the page contents of</p>
  
  <blockquote>
    <p>The Mojarra version is 2.2.5</p>
  </blockquote>
  
  <p>as I'd expect (I put the 2.2.5 jar into <code>glassfish/modules</code> some time back).  I then added the dependency for Mojarra 2.2.7 that I found from <a href="https://javaserverfaces.java.net/download.html" rel="nofollow noreferrer">the Mojarra Web Site</a>:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;dependency&gt;
    &lt;groupId&gt;org.glassfish&lt;/groupId&gt;
    &lt;artifactId&gt;javax.faces&lt;/artifactId&gt;
    &lt;version&gt;2.2.x&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>with "x" replaced by "7".  The resulting POM file looks like this (most of it is boilerplate from Netbeans):</p>
  
  <p><strong>POM.xml</strong>:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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/xsd/maven-4.0.0.xsd"&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
    &lt;groupId&gt;com.mycompany&lt;/groupId&gt;
    &lt;artifactId&gt;mavenproject1&lt;/artifactId&gt;
    &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
    &lt;packaging&gt;war&lt;/packaging&gt;
  
    &lt;name&gt;mavenproject1&lt;/name&gt;
  
    &lt;properties&gt;
      &lt;endorsed.dir&gt;${project.build.directory}/endorsed&lt;/endorsed.dir&gt;
      &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
    &lt;/properties&gt;
  
    &lt;dependencies&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;javax&lt;/groupId&gt;
        &lt;artifactId&gt;javaee-web-api&lt;/artifactId&gt;
        &lt;version&gt;7.0&lt;/version&gt;
        &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;org.glassfish&lt;/groupId&gt;
        &lt;artifactId&gt;javax.faces&lt;/artifactId&gt;
        &lt;version&gt;2.2.7&lt;/version&gt;
      &lt;/dependency&gt;
    &lt;/dependencies&gt;
  
    &lt;build&gt;
      &lt;plugins&gt;
        &lt;plugin&gt;
          &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
          &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
          &lt;version&gt;3.1&lt;/version&gt;
          &lt;configuration&gt;
            &lt;source&gt;1.8&lt;/source&gt;
            &lt;target&gt;1.8&lt;/target&gt;
            &lt;compilerArguments&gt;
              &lt;endorseddirs&gt;${endorsed.dir}&lt;/endorseddirs&gt;
            &lt;/compilerArguments&gt;
          &lt;/configuration&gt;
        &lt;/plugin&gt;
        &lt;plugin&gt;
          &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
          &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
          &lt;version&gt;2.3&lt;/version&gt;
          &lt;configuration&gt;
            &lt;failOnMissingWebXml&gt;false&lt;/failOnMissingWebXml&gt;
          &lt;/configuration&gt;
        &lt;/plugin&gt;
        &lt;plugin&gt;
          &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
          &lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;
          &lt;version&gt;2.6&lt;/version&gt;
          &lt;executions&gt;
            &lt;execution&gt;
              &lt;phase&gt;validate&lt;/phase&gt;
              &lt;goals&gt;
                &lt;goal&gt;copy&lt;/goal&gt;
              &lt;/goals&gt;
              &lt;configuration&gt;
                &lt;outputDirectory&gt;${endorsed.dir}&lt;/outputDirectory&gt;
                &lt;silent&gt;true&lt;/silent&gt;
                &lt;artifactItems&gt;
                  &lt;artifactItem&gt;
                    &lt;groupId&gt;javax&lt;/groupId&gt;
                    &lt;artifactId&gt;javaee-endorsed-api&lt;/artifactId&gt;
                    &lt;version&gt;7.0&lt;/version&gt;
                    &lt;type&gt;jar&lt;/type&gt;
                  &lt;/artifactItem&gt;
                &lt;/artifactItems&gt;
              &lt;/configuration&gt;
            &lt;/execution&gt;
          &lt;/executions&gt;
        &lt;/plugin&gt;
      &lt;/plugins&gt;
    &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>When I run the app, there is no difference in the output, it still shows version 2.2.5.  I found <a href="https://stackoverflow.com/questions/10782528/how-to-update-mojarra-version-in-glassfish">this article</a> with an answer from @BalusC that mentions Glassfish must be explicitly told to override the installed version of faces to use an alternate version deployed with the app, by putting this in <code>WEB-INF/glassfish-web.xml</code> for early versions of GF3:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;class-loader delegate="false" /&gt;
  &lt;property name="useBundledJsf" value="true" /&gt;
  </code></pre>
  
  <p>Even though I'm using GF4, I thought I'd give it a try, and added a <code>glassfish-web.xml</code> with this:</p>
  
  <p><strong>glassfish-web.xml</strong>:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;glassfish-web-app error-url=""&gt;
    &lt;class-loader delegate="false" /&gt;
    &lt;property name="useBundledJsf" value="true" /&gt;
  &lt;/glassfish-web-app&gt;
  </code></pre>
  
  <p>The result is a page that has shows the message with an empty version string:</p>
  
  <blockquote>
    <p>The Mojarra version is</p>
  </blockquote>
  
  <p>The GF log also indicates no errors.  The <code>.war</code> file that is created includes <code>WEB-INF/lib/javax.faces-2.2.7.jar</code>, so I suspect the problem has something to do with the GF configuration, rather than the Netbeans/Maven packaging.</p>
  
  <p>I know I can download the 2.2.7 jar and put it in the <code>glassfish/modules</code> directory (which is how I began using 2.2.5).   But the ultimate goal is to try alternate versions of JSF in an app-specific way (ideally, by just changing Maven coordinates for the JSF dependency), rather than change the GF install. Is there anyway to do this through configuration of the app and without altering the GF install?</p>
  
  <p><hr>
  Update 9/14/2015:
  I built a new Netbeans project:</p>
  
  <ul>
  <li>GlassFish 4.1 (out of the box), which has Mojarra 2.2.7, by default.</li>
  <li>NB Maven/Web Application project, with JSF 2.2 Framework.</li>
  <li>Modified the index.xhtml file as shown above.</li>
  <li>Added a Info.java class, containing the  contents, above (javax.enterprise.context.RequestScoped, javax.inject.Named).</li>
  <li>Added a WEB-INF/glassfish-web.xml and added the lines shown above.</li>
  <li>Added the dependency to the pom.xml file as shown above, but using javax.faces version 2.2.12.</li>
  </ul>
  
  <p>Essentially, I'm getting the same result.  If the useBundledJsf property setting is not in the glassfish-web.xml file, the version displays as 2.2.7 (even though the war file has 2.2.12 in it).  And if the useBundledJsf property setting is there, along with the change to the class-loader to "false", the version is blank.</p>
  
  <p>I also installed Mojarra 2.2.10 by changing the javax.faces file in the glassfish install to use 2.2.10.  When I do that, I get the same results -- either the version is empty, or it shows 2.2.10 (2.2.12 is still configured, and in the war in both cases).</p>