Hazelcast - 设置
Hazelcast 需要 Java 1.6 或更高版本。Hazelcast 还可以与 .NET、C++ 或其他基于 JVM 的语言(例如 Scala 和 Clojure)一起使用。但是,在本教程中,我们将使用 Java 8。
在继续之前,以下是我们将在本教程中使用的项目设置。
hazelcast/ ├── com.example.demo/ │ ├── SingleInstanceHazelcastExample.java │ ├── MultiInstanceHazelcastExample.java │ ├── Server.java │ └── .... ├── pom.xml ├── target/ ├── hazelcast.xml ├── hazelcast-multicast.xml ├── ...
现在,我们可以在 hazelcast 目录中创建包,即 com.example.demo。然后,只需 cd 到该目录即可。我们将在接下来的部分中查看其他文件。
安装 Hazelcast
安装 Hazelcast 只需将 JAR 文件添加到构建文件中即可。POM 文件或 build.gradle 分别取决于您使用的是 Maven 还是 Gradle。
如果您使用 Gradle,将以下内容添加到 build.gradle 文件就足够了 -
dependencies {
compile "com.hazelcast:hazelcast:3.12.12”
}
POM 教程
我们将在我们的教程中使用以下 POM -
<?xml version="1.0" encoding="UTF-8"?>
<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">
<modelVersion>1.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Hazelcast</description>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<version>3.12.12</version>
</dependency>
</dependencies>
<!-- Below build plugin is not needed for Hazelcast, it is being used only to created a shaded JAR so that -->
<!-- using the output i.e. the JAR becomes simple for testing snippets in the tutorial-->
<build>
<plugins>
<plugin>
<!-- Create a shaded JAR and specify the entry point class-->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>