Scalaのためのプロジェクトテンプレート

ビルドツール

Flink プロジェクトは異なるビルドツールを使ってビルドすることができます。素早く始めるために、Flinkは以下のビルドツールのためのプロジェクトテンプレートを提供します:

これらのテンプレートはプロジェクトの構造をセットアップし初期ビルドファイルを生成するのに役立ちます。

SBT

プロジェクトの生成

以下の2つの方法のどちらかを使って新しいプロジェクトの土台を作ることができます:

    $ sbt new tillrohrmann/flink-project.g8
    
これは数個のパラメータ(プロジェクト名、flinkバージョン...)の入力を促し、flink-project テンプレートからFlinkのプロジェクトを生成するでしょう。このコマンドを実行するには sbt >= 0.13.13 が必要です。必要であればそれを取得するために、このインストレーション ガイドに従うことができます。
    $ bash <(curl https://flink.apache.org/q/sbt-quickstart.sh)
    
これは特定の プロジェクト ディレクトリ内にFlinkプロジェクトを生成するでしょう。

プロジェクトのビルド

プロジェクトをビルドするためには、単純にsbt clean assembly コマンドを発行する必要があります。これは fat-jar your-project-name-assembly-0.1-SNAPSHOT.jartarget/scala_your-major-scala-version/ディレクトリに生成するでしょう。

プロジェクトの実行

プロジェクトを実行するには、sbt runコマンドを実行する必要があります。

デフォルトでは、sbt が実行しているのと同じJVM内でジョブを実行するでしょう。別個のJVM内でジョブを実行するには、以下の行をbuild.sbtに追加してください。

fork in run := true

IntelliJ

Flink ジョブ開発には、IntelliJの使用をお勧めします。開始するには、新しく生成されたプロジェクトをIntelliJにインポートする必要があります。これはFile -> New -> Project from Existing Sources...からプロジェクトのディレクトリを選択することで行うことができます。IntelliJ は自動的にbuild.sbt ファイルを検知し全てをセットアップすることができます。

Flinkジョブを実行するためには、Run/Debug ConfigurationのクラスパスとしてmainRunnerモジュールを選択することをお勧めします。これにより、providedに設定されている全ての依存が実行時に利用可能になることを確実にします。Run -> Edit Configurations...を使ってRun/Debug Configurations を設定し、Use classpath of module ドロップボックスからmainRunner を選択することができます。

Eclipse

新しく作成されたプロジェクトをEclipseにインポートするには、まずそのためのEclipseプロジェクトを生成する必要があります。これらのプロジェクトファイルはsbteclipse プラグインを使って生成することができます。以下の行を PROJECT_DIR/project/plugins.sbt ファイルに追加してください:

addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "4.0.0")

Eclipseプロジェクトファイルを生成するために、sbtの中で以下のコマンドを使用します

> eclipse

これで、File -> Import... -> Existing Projects into Workspace を使ってEclipseにプロジェクトをインポートし、プロジェクトディレクトリを選択することができます。

Maven

必要条件

The only requirements are working Maven 3.0.4 (or higher) and Java 8.x installations.

プロジェクトの生成

プロジェクトを作成するために以下のコマンドのうちの一つを使います:

    $ mvn archetype:generate                               \
      -DarchetypeGroupId=org.apache.flink              \
      -DarchetypeArtifactId=flink-quickstart-scala     \
      -DarchetypeCatalog=https://repository.apache.org/content/repositories/snapshots/ \
      -DarchetypeVersion=1.6-SNAPSHOT
    
これは新しく作成されたプロジェクトに名前を付けることができます。それは対話的に groupId, artifactId およびパッケージ名を尋ねます。
    $ curl https://flink.apache.org/q/quickstart-scala-SNAPSHOT.sh | bash

注意: Maven 3.0 以上については、コマンドラインを使ってレポジトリを指定 (-DarchetypeCatalog) することはもうできません。レポジトリのスナップショットを使いたい場合は、settings.xml にレポジトリのエントリを追加する必要があります。この変更についての詳細は、Maven公式ドキュメントを参照してください

プロジェクトの精査

作業ディレクトリ内に新しいディレクトリがあるでしょう。curl のやり方を使った場合は、ディレクトリはquickstartと呼ばれます。そうでなければ、それはartifactId の名前を持ちます。

$ tree quickstart/
quickstart/
├── pom.xml
└── src
    └── main
        ├── resources
        │   └── log4j.properties
        └── scala
            └── org
                └── myorg
                    └── quickstart
                        ├── BatchJob.scala
                        └── StreamingJob.scala

The sample project is a Maven project, which contains two classes: StreamingJob and BatchJob are the basic skeleton programs for a DataStream and DataSet program. The main method is the entry point of the program, both for in-IDE testing/execution and for proper deployments.

このプロジェクトをIDEにインポートすることをお勧めします。

IntelliJ IDEA supports Maven out of the box and offers a plugin for Scala development. From our experience, IntelliJ provides the best experience for developing Flink applications.

Eclipseについては、Eclipse Update Sitesからインストールすることができる以下のプラグインが必要です:

プロジェクトのビルド

If you want to build/package your project, go to your project directory and run the ‘mvn clean package’ command. You will find a JAR file that contains your application, plus connectors and libraries that you may have added as dependencoes to the application: target/<artifact-id>-<version>.jar.

Note: If you use a different class than StreamingJob as the application’s main class / entry point, we recommend you change the mainClass setting in the pom.xml file accordingly. That way, the Flink can run time application from the JAR file without additionally specifying the main class.

次のステップ

アプリケーションを書きます!

If you are writing a streaming application and you are looking for inspiration what to write, take a look at the Stream Processing Application Tutorial

If you are writing a batch processing application and you are looking for inspiration what to write, take a look at the Batch Application Examples

For a complete overview over the APIa, have a look at the DataStream API and DataSet API sections.

If you have any trouble, ask on our Mailing List. 喜んで手伝います。

上に戻る

TOP
inserted by FC2 system