Skip to content

Commit

Permalink
[FLINK-11612][docs-zh] Translate the "Project Template for Java" page…
Browse files Browse the repository at this point in the history
… into Chinese

This closes apache#8799
  • Loading branch information
yuezhuangshi authored and wuchong committed Jun 22, 2019
1 parent 00183f7 commit 9ef4b74
Showing 1 changed file with 75 additions and 90 deletions.
165 changes: 75 additions & 90 deletions docs/dev/projectsetup/java_api_quickstart.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,29 @@ under the License.
{:toc}


## Build Tools
## 构建工具

Flink projects can be built with different build tools.
In order to get started quickly, Flink provides project templates for the following build tools:
Flink项目可以使用不同的构建工具进行构建。
为了能够快速入门,Flink 为以下构建工具提供了项目模版:

- [Maven](#maven)
- [Gradle](#gradle)

These templates help you to set up the project structure and to create the initial build files.
这些模版可以帮助你搭建项目结构并创建初始构建文件。

## Maven

### Requirements
### 环境要求

The only requirements are working __Maven 3.0.4__ (or higher) and __Java 8.x__ installations.
唯一的要求是使用 __Maven 3.0.4__ (或更高版本)和安装 __Java 8.x__

### Create Project
### 创建项目

Use one of the following commands to __create a project__:
使用以下命令之一来 __创建项目__

<ul class="nav nav-tabs" style="border-bottom: none;">
<li class="active"><a href="#maven-archetype" data-toggle="tab">Use <strong>Maven archetypes</strong></a></li>
<li><a href="#quickstart-script" data-toggle="tab">Run the <strong>quickstart script</strong></a></li>
<li class="active"><a href="#maven-archetype" data-toggle="tab">使用 <strong>Maven archetypes</strong></a></li>
<li><a href="#quickstart-script" data-toggle="tab">运行 <strong>quickstart 脚本</strong></a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="maven-archetype">
Expand All @@ -60,7 +60,7 @@ Use one of the following commands to __create a project__:
-DarchetypeCatalog=https://repository.apache.org/content/repositories/snapshots/ \{% endunless %}
-DarchetypeVersion={{site.version}}
{% endhighlight %}
This allows you to <strong>name your newly created project</strong>. It will interactively ask you for the groupId, artifactId, and package name.
这种方式允许你<strong>为新项目命名</strong>。它将以交互式的方式询问你项目的 groupIdartifactId package 名称。
</div>
<div class="tab-pane" id="quickstart-script">
{% highlight bash %}
Expand All @@ -74,16 +74,17 @@ Use one of the following commands to __create a project__:
</div>
{% unless site.is_stable %}
<p style="border-radius: 5px; padding: 5px" class="bg-danger">
<b>Note</b>: For Maven 3.0 or higher, it is no longer possible to specify the repository (-DarchetypeCatalog) via the command line. If you wish to use the snapshot repository, you need to add a repository entry to your settings.xml. For details about this change, please refer to <a href="https://maven.apache.org/archetype/maven-archetype-plugin/archetype-repository.html">Maven official document</a>
<b>注意</b>:Maven 3.0 及更高版本,不再支持通过命令行指定仓库(-DarchetypeCatalog)。
如果你希望使用快照仓库,则需要在 settings.xml 文件中添加一个仓库条目。有关这个改动的详细信息,
请参阅 <a href="https://maven.apache.org/archetype/maven-archetype-plugin/archetype-repository.html">Maven 官方文档</a>
</p>
{% endunless %}
</div>

### Inspect Project
### 检查项目

There will be a new directory in your working directory. If you've used
the _curl_ approach, the directory is called `quickstart`. Otherwise,
it has the name of your `artifactId`:
项目创建后,工作目录将多出一个新目录。如果你使用的是 _curl_ 方式创建项目,目录名为 `quickstart`
如果你使用的是 _Maven archetypes_ 方式创建项目,则目录名为你指定的 `artifactId`

{% highlight bash %}
$ tree quickstart/
Expand All @@ -101,45 +102,40 @@ quickstart/
└── log4j.properties
{% endhighlight %}

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.
示例项目是一个 __Maven project__,它包含了两个类:_StreamingJob_ _BatchJob_ 分别是 *DataStream* and *DataSet* 程序的基础骨架程序。
_main_ 方法是程序的入口,既可用于IDE测试/执行,也可用于部署。

We recommend you __import this project into your IDE__ to develop and
test it. IntelliJ IDEA supports Maven projects out of the box.
If you use Eclipse, the [m2e plugin](https://www.eclipse.org/m2e/)
allows to [import Maven projects](https://books.sonatype.com/m2eclipse-book/reference/creating-sect-importing-projects.html#fig-creating-import).
Some Eclipse bundles include that plugin by default, others require you
to install it manually.
我们建议你将 __此项目导入IDE__ 来开发和测试它。
IntelliJ IDEA 支持 Maven 项目开箱即用。如果你使用的是 Eclipse,使用[m2e 插件](https://www.eclipse.org/m2e/) 可以
[导入 Maven 项目](https://books.sonatype.com/m2eclipse-book/reference/creating-sect-importing-projects.html#fig-creating-import)
一些 Eclipse 捆绑包默认包含该插件,其他情况需要你手动安装。

*Please note*: The default JVM heapsize for Java may be too
small for Flink. You have to manually increase it.
In Eclipse, choose `Run Configurations -> Arguments` and write into the `VM Arguments` box: `-Xmx800m`.
In IntelliJ IDEA recommended way to change JVM options is from the `Help | Edit Custom VM Options` menu. See [this article](https://intellij-support.jetbrains.com/hc/en-us/articles/206544869-Configuring-JVM-options-and-platform-properties) for details.
*请注意*:对 Flink 来说,默认的 JVM 堆内存可能太小,你应当手动增加堆内存。
在 Eclipse 中,选择 `Run Configurations -> Arguments` 并在 `VM Arguments` 对应的输入框中写入:`-Xmx800m`
在 IntelliJ IDEA 中,推荐从菜单 `Help | Edit Custom VM Options` 来修改 JVM 选项。有关详细信息,请参阅[这篇文章](https://intellij-support.jetbrains.com/hc/en-us/articles/206544869-Configuring-JVM-options-and-platform-properties)

### Build Project
### 构建项目

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 dependencies to the application: `target/<artifact-id>-<version>.jar`.
如果你想要 __构建/打包你的项目__,请在项目目录下运行 '`mvn clean package`' 命令。
命令执行后,你将 __找到一个JAR文件__,里面包含了你的应用程序,以及已作为依赖项添加到应用程序的连接器和库:`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, Flink
can run the application from the JAR file without additionally specifying the main class.
__注意:__ 如果你使用其他类而不是 *StreamingJob* 作为应用程序的主类/入口,
我们建议你相应地修改 `pom.xml` 文件中的 `mainClass` 配置。这样,
Flink 可以从 JAR 文件运行应用程序,而无需另外指定主类。

## Gradle

### Requirements
### 环境要求

The only requirements are working __Gradle 3.x__ (or higher) and __Java 8.x__ installations.
唯一的要求是使用 __Gradle 3.x__ (或更高版本) 和安装 __Java 8.x__

### Create Project
### 创建项目

Use one of the following commands to __create a project__:
使用以下命令之一来 __创建项目__

<ul class="nav nav-tabs" style="border-bottom: none;">
<li class="active"><a href="#gradle-example" data-toggle="tab"><strong>Gradle example</strong></a></li>
<li><a href="#gradle-script" data-toggle="tab">Run the <strong>quickstart script</strong></a></li>
<li class="active"><a href="#gradle-example" data-toggle="tab"><strong>Gradle 示例</strong></a></li>
<li><a href="#gradle-script" data-toggle="tab">运行 <strong>quickstart 脚本</strong></a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="gradle-example">
Expand Down Expand Up @@ -202,14 +198,13 @@ repositories {
maven { url "https://repository.apache.org/content/repositories/snapshots/" }
}

// NOTE: We cannot use "compileOnly" or "shadow" configurations since then we could not run code
// in the IDE or with "gradle run". We also cannot exclude transitive dependencies from the
// shadowJar yet (see https://github.com/johnrengelman/shadow/issues/159).
// -> Explicitly define the // libraries we want to be included in the "flinkShadowJar" configuration!
// 注意:我们不能使用 "compileOnly" 或者 "shadow" 配置,这会使我们无法在 IDE 中或通过使用 "gradle run" 命令运行代码。
// 我们也不能从 shadowJar 中排除传递依赖(请查看 https://github.com/johnrengelman/shadow/issues/159)。
// -> 显式定义我们想要包含在 "flinkShadowJar" 配置中的类库!
configurations {
flinkShadowJar // dependencies which go into the shadowJar

// always exclude these (also from transitive dependencies) since they are provided by Flink
// 总是排除这些依赖(也来自传递依赖),因为 Flink 会提供这些依赖。
flinkShadowJar.exclude group: 'org.apache.flink', module: 'force-shading'
flinkShadowJar.exclude group: 'com.google.code.findbugs', module: 'jsr305'
flinkShadowJar.exclude group: 'org.slf4j'
Expand All @@ -219,15 +214,15 @@ configurations {
// declare the dependencies for your production and test code
dependencies {
// --------------------------------------------------------------
// Compile-time dependencies that should NOT be part of the
// shadow jar and are provided in the lib folder of Flink
// 编译时依赖不应该包含在 shadow jar 中,
// 这些依赖会在 Flink 的 lib 目录中提供。
// --------------------------------------------------------------
compile "org.apache.flink:flink-java:${flinkVersion}"
compile "org.apache.flink:flink-streaming-java_${scalaBinaryVersion}:${flinkVersion}"

// --------------------------------------------------------------
// Dependencies that should be part of the shadow jar, e.g.
// connectors. These must be in the flinkShadowJar configuration!
// 应该包含在 shadow jar 中的依赖,例如:连接器。
// 它们必须在 flinkShadowJar 的配置中!
// --------------------------------------------------------------
//flinkShadowJar "org.apache.flink:flink-connector-kafka-0.11_${scalaBinaryVersion}:${flinkVersion}"

Expand Down Expand Up @@ -275,16 +270,13 @@ rootProject.name = 'quickstart'
{% highlight bash %}
bash -c "$(curl https://flink.apache.org/q/gradle-quickstart.sh)" -- {{site.version}} {{site.scala_version}}
{% endhighlight %}
This allows you to <strong>name your newly created project</strong>. It will interactively ask
you for the project name, organization (also used for the package name), project version,
Scala and Flink version.
这种方式允许你<strong>为新项目命名</strong>。它将以交互式的方式询问你的项目名称、组织机构(也用于包名)、项目版本、Scala 和 Flink 版本。
</div>
</div>

### Inspect Project
### 检查项目

There will be a new directory in your working directory based on the
project name you provided, e.g. for `quickstart`:
根据你提供的项目名称,工作目录中将多出一个新目录,例如 `quickstart`

{% highlight bash %}
$ tree quickstart/
Expand All @@ -304,51 +296,44 @@ quickstart/
└── log4j.properties
{% endhighlight %}

The sample project is a __Gradle 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.
示例项目是一个 __Gradle 项目__,它包含了两个类:_StreamingJob_ _BatchJob_ *DataStream* *DataSet* 程序的基础骨架程序。
_main_ 方法是程序的入口,即可用于IDE测试/执行,也可用于部署。

We recommend you __import this project into your IDE__ to develop and
test it. IntelliJ IDEA supports Gradle projects after installing the `Gradle` plugin.
Eclipse does so via the [Eclipse Buildship](https://projects.eclipse.org/projects/tools.buildship) plugin
(make sure to specify a Gradle version >= 3.0 in the last step of the import wizard; the `shadow` plugin requires it).
You may also use [Gradle's IDE integration](https://docs.gradle.org/current/userguide/userguide.html#ide-integration)
to create project files from Gradle.
我们建议你将 __此项目导入你的 IDE__ 来开发和测试它。
IntelliJ IDEA 在安装 `Gradle` 插件后支持 Gradle 项目。Eclipse 则通过 [Eclipse Buildship](https://projects.eclipse.org/projects/tools.buildship) 插件支持 Gradle 项目(鉴于 `shadow` 插件对 Gradle 版本有要求,请确保在导入向导的最后一步指定 Gradle 版本 >= 3.0)。
你也可以使用 [Gradle’s IDE integration](https://docs.gradle.org/current/userguide/userguide.html#ide-integration) 从 Gradle
创建项目文件。


*Please note*: The default JVM heapsize for Java may be too
small for Flink. You have to manually increase it.
In Eclipse, choose `Run Configurations -> Arguments` and write into the `VM Arguments` box: `-Xmx800m`.
In IntelliJ IDEA recommended way to change JVM options is from the `Help | Edit Custom VM Options` menu. See [this article](https://intellij-support.jetbrains.com/hc/en-us/articles/206544869-Configuring-JVM-options-and-platform-properties) for details.
*请注意*:对 Flink 来说,默认的 JVM 堆内存可能太小,你应当手动增加堆内存。
在 Eclipse中,选择 `Run Configurations -> Arguments` 并在 `VM Arguments` 对应的输入框中写入:`-Xmx800m`
在 IntelliJ IDEA 中,推荐从菜单 `Help | Edit Custom VM Options` 来修改 JVM 选项。有关详细信息,请参阅[此文章](https://intellij-support.jetbrains.com/hc/en-us/articles/206544869-Configuring-JVM-options-and-platform-properties)

### Build Project
### 构建项目

If you want to __build/package your project__, go to your project directory and
run the '`gradle clean shadowJar`' command.
You will __find a JAR file__ that contains your application, plus connectors and libraries
that you may have added as dependencies to the application: `build/libs/<project-name>-<version>-all.jar`.
如果你想要 __构建/打包项目__,请在项目目录下运行 '`gradle clean shadowJar`' 命令。
命令执行后,你将 __找到一个 JAR 文件__,里面包含了你的应用程序,以及已作为依赖项添加到应用程序的连接器和库:`build/libs/<project-name>-<version>-all.jar`

__Note:__ If you use a different class than *StreamingJob* as the application's main class / entry point,
we recommend you change the `mainClassName` setting in the `build.gradle` file accordingly. That way, Flink
can run the application from the JAR file without additionally specifying the main class.
__注意:__ 如果你使用其他类而不是 *StreamingJob* 作为应用程序的主类/入口,
我们建议你相应地修改 `build.gradle` 文件中的 `mainClassName` 配置。
这样,Flink 可以从 JAR 文件运行应用程序,而无需另外指定主类。

## Next Steps
## 下一步

Write your application!
开始编写应用!

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]({{ site.baseurl }}/tutorials/datastream_api.html#writing-a-flink-program).
如果你准备编写流处理应用,正在寻找灵感来写什么,
可以看看[流处理应用程序教程]({{ site.baseurl }}/zh/tutorials/datastream_api.html#writing-a-flink-program)

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]({{ site.baseurl }}/dev/batch/examples.html).
如果你准备编写批处理应用,正在寻找灵感来写什么,
可以看看[批处理应用程序示例]({{ site.baseurl }}/zh/dev/batch/examples.html)

For a complete overview over the APIs, have a look at the
[DataStream API]({{ site.baseurl }}/dev/datastream_api.html) and
[DataSet API]({{ site.baseurl }}/dev/batch/index.html) sections.
有关 API 的完整概述,请查看
[DataStream API]({{ site.baseurl }}/zh/dev/datastream_api.html)
[DataSet API]({{ site.baseurl }}/zh/dev/batch/index.html) 章节。

[Here]({{ site.baseurl }}/tutorials/local_setup.html) you can find out how to run an application outside the IDE on a local cluster.
[这里]({{ site.baseurl }}/zh/tutorials/local_setup.html),你可以找到如何在 IDE 之外的本地集群中运行应用程序。

If you have any trouble, ask on our
[Mailing List](https://mail-archives.apache.org/mod_mbox/flink-user/).
We are happy to provide help.
如果你有任何问题,请发信至我们的[邮箱列表](https://mail-archives.apache.org/mod_mbox/flink-user/),我们很乐意提供帮助。

{% top %}

0 comments on commit 9ef4b74

Please sign in to comment.