1. Configuring the Infinispan Maven Repository
Infinispan Java distributions are available from Maven.
Infinispan artifacts are available from Maven central. See the org.infinispan group for available Infinispan artifacts.
1.1. Configuring Your Infinispan POM
Maven uses configuration files called Project Object Model (POM) files to define projects and manage builds. POM files are in XML format and describe the module and component dependencies, build order, and targets for the resulting project packaging and output.
-
Open your project
pom.xmlfor editing. -
Define the
version.infinispanproperty with the correct Infinispan version. -
Include the
infinispan-bomin adependencyManagementsection.The Bill Of Materials (BOM) controls dependency versions, which avoids version conflicts and means you do not need to set the version for each Infinispan artifact you add as a dependency to your project.
-
Save and close
pom.xml.
The following example shows the Infinispan version and BOM:
<properties>
<version.infinispan>10.1.8.Final</version.infinispan>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-bom</artifactId>
<version>${version.infinispan}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Add Infinispan artifacts as dependencies to your pom.xml as required.
2. Installing Infinispan in Library Mode
Add Infinispan as an embedded library in your project.
-
Add the
infinispan-coreartifact as a dependency in yourpom.xmlas follows:
<dependencies>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-core</artifactId>
</dependency>
</dependencies>
3. Running Infinispan as an Embedded Library
Learn how to run Infinispan as an embedded data store in your project.
-
Initialize the default Cache Manager and add a cache definition as follows:
GlobalConfigurationBuilder global = GlobalConfigurationBuilder.defaultClusteredBuilder();
DefaultCacheManager cacheManager = new DefaultCacheManager(global.build());
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.clustering().cacheMode(CacheMode.DIST_SYNC);
cacheManager.administration().withFlags(CacheContainerAdmin.AdminFlag.VOLATILE).getOrCreateCache("myCache", builder.build());
The preceding code initializes a default, clustered Cache Manager. Cache Managers contain your cache definitions and control cache lifecycles.
Infinispan does not provide default cache definitions so after initializing
the default Cache Manager, you need to add at least one cache instance. This
example uses the ConfigurationBuilder class to create a cache definition that
uses the distributed, synchronous cache mode. You then call the
getOrCreateCache() method that either creates a cache named "myCache" on all
nodes in the cluster or returns it if it already exists.
Now that you have a running Cache Manager with a cache created, you can add some more cache definitions, put some data into the cache, or configure Infinispan as needed.