flink开发环境搭建、maven环境搭建、IDEA环境搭建

目录:

 Go To End


 

maven环境搭建

  maven 下载https://maven.apache.org/download.cgi ,你也可以使用wget + url 下载。

    命令:wget http://mirrors.advancedhosters.com/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz

    我下载的是3.6.3的版本,目前要求JDK 1.7或更高版本才能执行。

  解压缩:命令:tar zvxf apache-maven-3.6.3-bin.tar.gz

  安装

    这里我先生成了maven-install文件夹,apache-maven-3.6.3文件夹放在此文件夹中,现在修改maven镜像。进入maven的conf文件夹(在bin同级目录下),使用 vim settings.xml 编辑文本,输入反斜杠‘/’,搜索mirrors,按enter定位。设置如下代码:

<mirror>
      <id>alimaven</id>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>
</mirror>

    参考文献:Linux安装maven

  配置环境变量

    我先建立了apache-maven-3.6.3的软连接,命令:ln -s apache-maven-3.6.3 maven

    配置环境变量:sudo vim /etc/profile

      添加如下代码:

#maven
export MAVEN_HOME=/home/elfin/maven-install/maven
export PATH=$PATH:$MAVEN_HOME/bin

    刷新配置:source /etc/profile

  验证maven安装是否成功:mvn -v

  

 

  可以看见已经安装成功了,返回了maven的版本以及Java的版本。

Back To Top    Go To End


 

IDEA环境搭建

  下载安装包,地址:https://download-cf.jetbrains.com/idea/ideaIC-2020.1.tar.gz

  解压缩:tar zvxf idealC-2020.1.tar.gz

  创建桌面快捷方式:

    命令1:touch idea.desktop 生成桌面文件

    命令2:vim idea.desktop  添加代码:

[Desktop Entry]
Name=IntelliJ IDEA
Comment=IntelliJ IDEA
Exec=/home/elfin/idea-install/idea-IC-201.6668.121/bin/idea.sh
Icon=/home/elfin/idea-install/idea-IC-201.6668.121/bin/idea.png
Terminal=false
Type=Application
Categories=Developer;

    其中Exec指向你的启动文件,Icon指向图片。

    命令3:chmod u+x idea.desktop 赋予权限

    

 

   图标不正常显示:双击桌面快捷方式,选择信任,图标就正常显示了。

 

 

Back To Top    Go To End


 

 

flink开发环境搭建

    创建flink项目

  方式一:curl https://flink.apache.org/q/quickstart.sh | bash -s 1.9.2

    你可以打开脚本文件:https://flink.apache.org/q/quickstart.sh 代码如下:

#!/usr/bin/env bash

################################################################################
#  Licensed to the Apache Software Foundation (ASF) under one
#  or more contributor license agreements.  See the NOTICE file
#  distributed with this work for additional information
#  regarding copyright ownership.  The ASF licenses this file
#  to you under the Apache License, Version 2.0 (the
#  "License"); you may not use this file except in compliance
#  with the License.  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
# limitations under the License.
################################################################################


PACKAGE=quickstart

mvn archetype:generate                                \
  -DarchetypeGroupId=org.apache.flink                \
  -DarchetypeArtifactId=flink-quickstart-java        \
  -DarchetypeVersion=${1:-1.10.0}                            \
  -DgroupId=org.myorg.quickstart                    \
  -DartifactId=$PACKAGE                                \
  -Dversion=0.1                                        \
  -Dpackage=org.myorg.quickstart                    \
  -DinteractiveMode=false

#
# Give some guidance
#
echo -e "\\n\\n"
echo -e "\\tA sample quickstart Flink Job has been created."
echo -e "\\tSwitch into the directory using"
echo -e "\\t\\t cd $PACKAGE"
echo -e "\\tImport the project there using your favorite IDE (Import it as a maven project)"
echo -e "\\tBuild a jar inside the directory using"
echo -e "\\t\\t mvn clean package"
echo -e "\\tYou will find the runnable jar in $PACKAGE/target"
echo -e "\\tConsult our website if you have any troubles: http://flink.apache.org/community.html#mailing-lists"
echo -e "\\n\\n"

    命令使用详情:第一次使用会下载很多包,下载时间较长,需要稍加等待。

    

    

    

    这里面已经默认为你配置好了,但是有时我们想要自己配置,那么我们可以使用方式二。

  方式二:注意 \ 是终端换行符号,以下代码不能直接复制,因为格式的缘故,可能会出问题。

    $ mvn archetype:generate \

    -DarchetypeGroupId=org.apache.flink \

    -DarchetypeArtifactId=flink-quickstart-java \

    -DarchetypeVersion=1.9.2

    当然可以直接一行写出所有的命令行参数:  

    mvn archetype:generate -DarchetypeGroupId=org.apache.flink -DarchetypeArtifactId=flink-quickstart-java -DarchetypeVersion=1.9.2 -DarchetypeCatalog=internal

    最后一个参数如果不加,你的创建过程可能会非常非常漫长,当然你可以下载相关文件到本地,然后令此参数为local。

  

 

  

 

  创建成功。我们尝试用命令:mvn archetype:generate -DarchetypeGroupId=org.apache.flink -DarchetypeArtifactId=flink-quickstart-java -DarchetypeVersion=1.9.2 -DarchetypeCatalog=local 创建,同样也成功了。

    IDEA-flink开发环境

  IDEA导入已经创建的环境:打开IDEA之后open对应的项目,在terminal里输入:mvn clean package 打包项目(编译项目),clean是清除之前的打包。

  

    核心依赖

  打包时,核心依赖不会进行打包,因为核心依赖要尽可能小,避免冲突,一般运行环境都有这些包。核心依赖包含coordination、networking、checkpoints、failover、APIs、operations、resource management等必须的依赖。

    应用依赖

 

核心依赖、应用依赖等都在porm.xml文件里可以进行配置。

  groupId标签:一般我们设置为域名的顺序倒置,如org.flink

  artifactId标签:可以理解为项目名

  version标签:项目版本号,默认为:1.0-SNAPSHOT

  packaging标签:我这里是jar包,因为使用Java开发

  repositories标签:配置数仓信息,你可以配置公司的信息

  dependencies标签:依赖,包含标签<scope>provided</scope>的是核心依赖,所以不是核心依赖就不要写这个子标签,不然打包时这个依赖不会配置。应用依赖使用的子标签是:<scope>runtime</scope>,注意与核心依赖的区分。

  build标签:是打包编译时要配置的插件

 

 

Back To Top    Go To End


 

 

 


 

posted @ 2020-04-22 22:28  巴蜀秀才  阅读(3840)  评论(0编辑  收藏  举报