title: JAR libraries in WEB-INF/lib not added to classpath during Glassfish deployment
body: <p>I'm new to Glassfish and Java EE although I've been using Java for a few years. I've inherited a project that stalled and now I need to start development on it again. I'm trying to deploy the web application as-is to see what works and what needs attention. While there is a lot of code to implement various functions, it appears that the first point needing attention is deployment of the application.</p>
  
  <p>The web application I'm trying to deploy is <code>MyServer</code> and is packaged in a WAR archive. A class in <code>MyServer</code> has a reference to a class in <code>MyDatabase</code> which implements an interface (<code>InterfaceOne</code>) from <code>MyInterfaces</code>. The class in <code>MyServer</code> also has a direct reference to <code>InterfaceOne</code> from <code>MyInterfaces</code>. <code>MyServer</code>, <code>MyDatabase</code> and <code>MyInterfaces</code> are all projects in Eclipse and packaged using Maven. The <code>MyServer</code> POM file lists <code>MyDatabase</code> as a dependency and the POM file for <code>MyDatabase</code> lists <code>MyInterfaces</code> as a dependency. The <code>MyServer</code> POM file doesn't list <code>MyInterfaces</code> as an immediate dependency but I don't think that this should cause an issue. Eclipse doesn't show any errors in the <code>MyServer</code> class concerned; Eclipse appears to consider the Maven dependencies to be sufficient to locate all necessary classes.</p>
  
  <p>When I deploy the <code>MyServer</code> WAR on Glassfish v3.1.2 via the Admin web console and then view the logs in <code>~glassfish3/glassfish/domains/MyDomain/logs/server.log</code> I encounter the following errors:</p>
  
  <blockquote>
    <p>[#|2014-05-29T10:06:02.371+0100|SEVERE|glassfish3.1.2|global|_ThreadID=80;_ThreadName=Thread-2;| Class [ my/interfaces/InterfaceOne] not found. Error while loading [ class my.server.ControllerOne ]|#]
    [#|2014-05-29T10:06:02.387+0100|SEVERE|glassfish3.1.2|global|_ThreadID=80;_ThreadName=Thread-2;|Class [ my/interfaces/InterfaceOne ] not found. Error while loading [ class my.server.ControllerOne ]|#]</p>
  </blockquote>
  
  <p>There are two errors shown relating to the interface while trying to load the class from <code>MyServer</code>. If I remove either the reference to <code>MyDatabase</code> or the direct reference to <code>InterfaceOne</code> from <code>MyInterfaces</code> from the <code>my.server.ControllerOne</code> class then one of the errors above disappears (which is expected and just confirms that the error is related to the references (directly and indirectly) of the <code>InterfaceOne</code> from <code>MyInterfaces</code>.</p>
  
  <p>Similar questions including <a href="https://stackoverflow.com/questions/16782109">here</a>, <a href="https://stackoverflow.com/questions/4044350">here</a> and <a href="https://stackoverflow.com/questions/9560943">here</a> all mention ensuring that the required libraries (<code>my-database.jar</code> and <code>my-interfaces.jar</code>) are located in the <code>WEB-INT/lib</code> directory of the <code>MyServer</code> application's WAR archive. However, if I inspect the generated WAR archive for <code>MyServer</code> then the libraries are indeed located in the <code>WEB-INF/lib/</code> directory. If I inspect the <code>~glassfish3/glassfish/domains/MyDomain/applications/MyServer/WEB-INF/lib/</code> directory after deployment the libraries are there too. I assume this indicates that they were successfully extracted from the WAR archive and placed on the Glassfish server. The point is the libraries are definitely there!</p>
  
  <p>All I can think of is that the libraries are not added to classpath of the JVM trying to load the classes of <code>MyServer</code> but surely if Glassfish tries to load classes of an application then it should also first load the libraries packaged with the application shouldn't it? Indeed <a href="http://docs.oracle.com/cd/E26576_01/doc.312/e24930/class-loaders.htm" rel="nofollow noreferrer">this</a> page from the Oracle GlassFish Server Application Development Guide
  Release 3.1.2 indicates that the <code>WEB-INF/lib/</code> directory of an application is added to the application's classpath.</p>
  
  <p>I've seen other suggestions that libraries required by web applications be placed in the <code>~glassfish3/glassfish/domains/MyDomain/lib/ext/</code> directory. That might very well work but my specific libraries are required by the <code>MyServer</code> application only, not the whole of <code>MyDomain</code>. As far as I can tell, it should be valid to place them in the <code>WEB-INF/lib/</code> directory of my application.</p>
  
  <p>Does anyone have any ideas about why the <code>my-database.jar</code> and <code>my-interfaces.jar</code> libraries don't seem to be added to the classpath during deployment? More specifically, does anyone know why the <code>my.interfaces.InterfaceOne</code> class isn't visible while loading the <code>my.server.ControllerOne</code> class during deployment?</p>
  
  <p><code>MyServer</code>'s <code>web.xml</code> content:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"&gt;
    &lt;display-name&gt;MyServer&lt;/display-name&gt;
    &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;index.xhtml&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.xhtml&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
    &lt;servlet&gt;
      &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/faces/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
    &lt;context-param&gt;
      &lt;description&gt;State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2&lt;/description&gt;
      &lt;param-name&gt;javax.faces.STATE_SAVING_METHOD&lt;/param-name&gt;
      &lt;param-value&gt;client&lt;/param-value&gt;
    &lt;/context-param&gt;
    &lt;context-param&gt;
      &lt;param-name&gt;javax.servlet.jsp.jstl.fmt.localizationContext&lt;/param-name&gt;
      &lt;param-value&gt;resources.application&lt;/param-value&gt;
    &lt;/context-param&gt;
    &lt;context-param&gt;
      &lt;param-name&gt;javax.faces.FACELETS_LIBRARIES&lt;/param-name&gt;
      &lt;param-value&gt;/WEB-INF/balusc.taglib.xml&lt;/param-value&gt;
    &lt;/context-param&gt;
    &lt;context-param&gt;
      &lt;param-name&gt;javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL&lt;/param-name&gt;
      &lt;param-value&gt;true&lt;/param-value&gt;
    &lt;/context-param&gt;
    &lt;filter&gt;
      &lt;filter-name&gt;PrimeFaces FileUpload Filter&lt;/filter-name&gt;
      &lt;filter-class&gt;org.primefaces.webapp.filter.FileUploadFilter&lt;/filter-class&gt;
    &lt;/filter&gt;
    &lt;filter-mapping&gt;
      &lt;filter-name&gt;PrimeFaces FileUpload Filter&lt;/filter-name&gt;
      &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
    &lt;/filter-mapping&gt;
    &lt;context-param&gt;
      &lt;param-name&gt;javax.faces.PARTIAL_STATE_SAVING&lt;/param-name&gt;
      &lt;param-value&gt;false&lt;/param-value&gt;
    &lt;/context-param&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>MyServer pom.xml</p>
  
  <pre><code>&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;my.webapp&lt;/groupId&gt;
      &lt;artifactId&gt;my-server&lt;/artifactId&gt;
      &lt;version&gt;0.1.0-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;My Server&lt;/name&gt;
      &lt;parent&gt;
          &lt;groupId&gt;my.webapp&lt;/groupId&gt;
          &lt;artifactId&gt;my-parent-pom&lt;/artifactId&gt;
          &lt;version&gt;1.5&lt;/version&gt;
      &lt;/parent&gt;
      &lt;organization&gt;
          &lt;name&gt;Example&lt;/name&gt;
          &lt;url&gt;http://www.example.com&lt;/url&gt;
      &lt;/organization&gt;
      &lt;repositories&gt;
          &lt;repository&gt;
              &lt;id&gt;eclipselink&lt;/id&gt;
              &lt;url&gt;http://www.eclipse.org/downloads/download.php?r=1&amp;amp;nf=1&amp;amp;file=/rt/eclipselink/maven.repo/&lt;/url&gt;
          &lt;/repository&gt;
      &lt;/repositories&gt;
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax&lt;/groupId&gt;
              &lt;artifactId&gt;javaee-api&lt;/artifactId&gt;
              &lt;version&gt;6.0&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.faces&lt;/groupId&gt;
              &lt;artifactId&gt;jsf-api&lt;/artifactId&gt;
              &lt;version&gt;2.1&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.sun.faces&lt;/groupId&gt;
              &lt;artifactId&gt;jsf-impl&lt;/artifactId&gt;
              &lt;version&gt;2.1.0&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;eclipselink&lt;/groupId&gt;
              &lt;artifactId&gt;eclipselink&lt;/artifactId&gt;
              &lt;version&gt;2.3.0&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;utilities&lt;/groupId&gt;
              &lt;artifactId&gt;utilities&lt;/artifactId&gt;
              &lt;version&gt;0.1.0&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;javax.enterprise&lt;/groupId&gt;
              &lt;artifactId&gt;cdi-api&lt;/artifactId&gt;
              &lt;version&gt;1.0&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;my.webapp&lt;/groupId&gt;
              &lt;artifactId&gt;my-database&lt;/artifactId&gt;
              &lt;version&gt;0.1.0-SNAPSHOT&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.primefaces&lt;/groupId&gt;
              &lt;artifactId&gt;primefaces&lt;/artifactId&gt;
              &lt;version&gt;3.4.1&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.commons&lt;/groupId&gt;
          &lt;artifactId&gt;commons-io&lt;/artifactId&gt;
          &lt;version&gt;1.3.2&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;commons-fileupload&lt;/groupId&gt;
          &lt;artifactId&gt;commons-fileupload&lt;/artifactId&gt;
          &lt;version&gt;1.2.1&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;packaging&gt;war&lt;/packaging&gt;
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
                  &lt;!-- &lt;configuration&gt; section added to pick up the WEB-INF/web.xml inside
                      WebContent --&gt;
                  &lt;configuration&gt;
                      &lt;webResources&gt;
                          &lt;resource&gt;
                              &lt;directory&gt;WebContent&lt;/directory&gt;
                          &lt;/resource&gt;
                      &lt;/webResources&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
      &lt;scm&gt;
          &lt;connection&gt;scm:svn:https://svn.server/location/in/repo/my_server&lt;/connection&gt;
          &lt;developerConnection&gt;scm:svn:https://svn.server/location/in/repo/my_server/trunk&lt;/developerConnection&gt;
      &lt;/scm&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>MyDatabase pom.xml</p>
  
  <pre><code>&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;artifactId&gt;my-database&lt;/artifactId&gt;
    &lt;version&gt;0.1.0-SNAPSHOT&lt;/version&gt;
    &lt;parent&gt;
      &lt;groupId&gt;my.webapp&lt;/groupId&gt;
      &lt;artifactId&gt;my-parent-pom&lt;/artifactId&gt;
      &lt;version&gt;1.5&lt;/version&gt;
    &lt;/parent&gt;
    &lt;dependencies&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;eclipselink&lt;/groupId&gt;
        &lt;artifactId&gt;eclipselink&lt;/artifactId&gt;
        &lt;version&gt;2.3.0&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;junit&lt;/groupId&gt;
          &lt;artifactId&gt;junit&lt;/artifactId&gt;
          &lt;version&gt;4.10&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;org.mindrot&lt;/groupId&gt;
        &lt;artifactId&gt;bcrypt&lt;/artifactId&gt;
        &lt;version&gt;0.2.0&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;my.webapp&lt;/groupId&gt;
          &lt;artifactId&gt;my-interfaces&lt;/artifactId&gt;
          &lt;version&gt;0.1.0-SNAPSHOT&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.geronimo.specs&lt;/groupId&gt;
          &lt;artifactId&gt;geronimo-jpa_3.0_spec&lt;/artifactId&gt;
          &lt;version&gt;1.1.1&lt;/version&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;mysql&lt;/groupId&gt;
          &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
          &lt;version&gt;5.0.5&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
    &lt;/dependencies&gt;
    &lt;scm&gt;
      &lt;connection&gt;scm:svn:https://svn.server/location/in/repo/my_database&lt;/connection&gt;
      &lt;developerConnection&gt;scm:svn:https://svn.server/location/in/repo/my_database/trunk/&lt;/developerConnection&gt;
    &lt;/scm&gt;
    &lt;groupId&gt;my.webapp&lt;/groupId&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>MyInterfaces pom.xml</p>
  
  <pre><code>&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;my.webapp&lt;/groupId&gt;
    &lt;artifactId&gt;my-interfaces&lt;/artifactId&gt;
    &lt;version&gt;0.1.0-SNAPSHOT&lt;/version&gt;
     &lt;packaging&gt;jar&lt;/packaging&gt;
    &lt;parent&gt;
        &lt;groupId&gt;my.webapp&lt;/groupId&gt;
        &lt;artifactId&gt;my-parent-pom&lt;/artifactId&gt;
        &lt;version&gt;1.5&lt;/version&gt;
  
    &lt;/parent&gt;
    &lt;scm&gt;
      &lt;connection&gt;scm:svn:https://svn.server/location/in/repo/my_interfaces&lt;/connection&gt;
      &lt;developerConnection&gt;scm:svn:https://svn.server/location/in/repo/my_interfaces/trunk&lt;/developerConnection&gt;
    &lt;/scm&gt;
    &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;my.webapp&lt;/groupId&gt;
          &lt;artifactId&gt;my-utilities&lt;/artifactId&gt;
          &lt;version&gt;0.1.2&lt;/version&gt;
          &lt;classifier&gt;me&lt;/classifier&gt;
      &lt;/dependency&gt;
        &lt;dependency&gt;
        &lt;groupId&gt;javax&lt;/groupId&gt;
        &lt;artifactId&gt;javaee-api&lt;/artifactId&gt;
        &lt;version&gt;6.0&lt;/version&gt;
        &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;junit&lt;/groupId&gt;
        &lt;artifactId&gt;junit&lt;/artifactId&gt;
        &lt;version&gt;4.10&lt;/version&gt;
        &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
        &lt;/dependencies&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>The <code>MyInterfaces</code> POM lists a dependency on <code>MyUtilities</code>. I think this can be safely ignored for this question since none of it's classes appear in the error messages I've described. It is also placed in the <code>WEB-INT/lib/</code> directory on the Glassfish server when my application is deployed.</p>
  
  <p>(Glassfish questions appear to require a lot of info like web.xml files and pom.xml etc. Thanks for taking the time to sift through all of this.)</p>