Hazelcast 简明教程
Hazelcast - Setup
Hazelcast 要求 Java 1.6 或更高版本。Hazelcast 还可以与 .NET、C++ 或其他基于 JVM 的语言(如 Scala 和 Clojure)一起使用。不过,对于本教程,我们将使用 Java 8。
Hazelcast requires Java 1.6 or above. Hazelcast can also be used with .NET, C++, or other JVM based languages like Scala and Clojure. However, for this tutorial, we are going to use Java 8.
在我们继续之前,以下是我们将用于本教程的项目设置。
Before we move on, following is the project setup that we will use for this tutorial.
hazelcast/
├── com.example.demo/
│ ├── SingleInstanceHazelcastExample.java
│ ├── MultiInstanceHazelcastExample.java
│ ├── Server.java
│ └── ....
├── pom.xml
├── target/
├── hazelcast.xml
├── hazelcast-multicast.xml
├── ...
现在,我们只需在 hazelcast 目录中创建包,即 com.example.demo。然后,直接 cd 到该目录。我们将在即将到来的部分中查看其他文件。
For now, we can just create the package, i.e., com.example.demo inside the hazelcast directory. Then, just cd to that directory. We will look at other files in the upcoming sections.
Installing Hazelcast
安装 Hazelcast 只需将 JAR 文件添加到您的构建文件。基于您使用 Maven 或 Gradle,POM 文件或 build.gradle。
Installing Hazelcast simply involves adding a JAR file to your build file. POM file or build.gradle based on whether you are using Maven or Gradle respectively.
如果您使用 Gradle,将以下内容添加到 build.gradle 文件中就足够了−
If you are using Gradle, adding the following to build.gradle file would be enough −
dependencies {
compile "com.hazelcast:hazelcast:3.12.12”
}
POM for the tutorial
我们将在教程中使用以下 POM −
We will use the following POM for our tutorial −
<?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>