11.2. Class Sharing


Private class space

By default, a FAB adds each Maven dependency to its private class space at run time (except for dependencies having Maven group ID org.apache.camel, org.apache.activemq, or org.apache.cxf, which are shared by default). This is a safe approach to deploying dependencies, because it reduces the risk of version inconsistencies. But it is also an expensive approach, in terms of resources, because it forces the JVM to maintain a dedicated copy of each dependency in memory, just for this FAB.

Shared class space

You can make a FAB more economical by opting to share some of its dependencies with other applications in the container. There are two approaches you can use:

Specify shared dependencies using provided scope

To share a dependency (and its transitive dependencies), declare a dependency with the provided scope in your project's pom.xml file. For example:
<dependency>
  <groupId>org.acme.foo</groupId>
  <artifactId>foo-core</artifactId>
  <version>${foo-version}</version>
 <scope>provided</scope>
</dependency>
This is analogous to the approach you would use when building a WAR with Maven, in order to avoid including libraries like the servlet API or the JSP API.

Specify shared dependencies using Manifest header

You can also configure class sharing by setting the FAB-Provided-Dependency: manifest header. For example, to share all artifacts with the org.acme.foo Maven group ID:
FAB-Provided-Dependency: org.acme.foo:* org.apache.camel:* org.apache.cxf:* org.apache.activemq:*
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.