Flink how to build the project, Flink quickly develop applications?

Project Templates

Flink application can use the Maven project to build the project or SBT, Flink provides the appropriate project templates for building these tools.
Maven command as follows template, we only need to groupId prompted for application projects, artifactId, version and package path.


mvn archetype:generate -DarchetypeGroupId=org.apache.flink -DarchetypeArtifactId=flink-quickstart-java -DarchetypeVersion=1.7.2

We use the IDEA directory structure and create the directory structure is basically the same, but it will help us to introduce Flink rely on and log-dependent.

<flink.version>1.7.2</flink.version>
<scala.binary.version>2.11</scala.binary.version>
...
<dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-java</artifactId>
            <version>${flink.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-streaming-java_${scala.binary.version}</artifactId>
            <version>${flink.version}</version>
            <scope>provided</scope>
        </dependency>
        

flink-java and flink-streaming-java_2.11 is necessary to rely on our use of Java development Flink applications.

The default also help us to introduce maven-shade-plugin plugin, so remember to mainClass into their main class in the package when.

Flink application development dependencies can be divided into two categories:

  • Flink core dependent (Flink core Dependencies): It is required to run the system Flink classes and dependencies, which is dependent on the project's core code and Flink used. For example implementation: scheduling, communications, checkpoint, API and the like. We introduced above is the core Flink dependence, we only need to rely for core-dependent effect can range scope set provided, that is not to rely on into the jar package. Because these core reliance, Flink run the cluster can provide for us.
  • Application relies on (User Application Dependencies): This part is dependent on a number of other items that we needed to develop applications, such as connectors, formatting library, Flink CEP, Flink SQL, Flink ML and so on. When packaged applications, we need to rely on these terms with our application code together into a jar package
//Flink核心依赖
<dependency>
  <groupId>org.apache.flink</groupId>
  <artifactId>flink-java</artifactId>
  <version>1.7.2</version>
  <scope>provided</scope>
</dependency>
<dependency>
  <groupId>org.apache.flink</groupId>
  <artifactId>flink-streaming-java_2.11</artifactId>
  <version>1.7.2</version>
  <scope>provided</scope>
</dependency>
//应用程序依赖
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-connector-kafka-0.10_2.11</artifactId>
    <version>1.7.2</version>
</dependency>

to sum up

This paper focuses on how to use Maven build tool to quickly build different projects and Flink Flink core dependency and applications that rely on to do the explaining, we need to pay attention to the core rely only need to rely scope scope to set provided.

Guess you like

Origin www.cnblogs.com/bigdata1024/p/11938727.html