Simple ways to change the default lib directory in an ear file

 An EAR file may contain a directory that contains libraries packaged in JAR files used by some of its components. By default, all JAR files included in the lib folder will be available to all applications packages in the EAR file.

You can however override the location of the library directory by configuring the library-directory parameter in your META-INF/application.xml file. See as an example:

<application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd">
   <module>
      <ejb>hello-ejb.jar</ejb>
   </module>
   <module>
      <web>
         <web-uri>myapp.war</web-uri>
         <context-root>myapp</context-root>
      </web>
   </module>
   <library-directory>APP-INF/lib</library-directory>
</application>

All files in the library-directory (but not in subdirectories) with a .jar extension will be available to all components packaged in the EAR file, including application clients. These libraries may reference other libraries, either bundled with the application or installed separately.

As an alternative, you can include the same parameter in your jboss-app.xml. Here’s an example:

<application>
  <display-name>My Application</display-name>
  <module>
    <web>
      <web-uri>myapp.war</web-uri>
      <context-root>/myapp</context-root>
    </web>
  </module>

  <module>
    <ejb>myapp.jar</ejb>
  </module>
  
  <library-directory>APP-INF/lib</library-directory>

</application>

Conclusion

The Jakarta EE platform provides several mechanisms for applications to use optional packages and shared libraries. In this tutorial we have learned the standard way to bundle the shared JAR files in an EAR and how to override this default setting.