首先,上來什麼也不說,先感謝這位大佬的傑出貢獻。提點了小弟。
剛剛接觸Flink,磕磕絆絆的寫了一些Flink的代碼,本想着打包到服務器上跑一下。結果給我報錯
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check (validate) on project dsssanaly: Failed during checkstyle execution: Unable to find suppressions file at location: /tools/maven/suppressions.xml: Could not find resource '/tools/maven/suppressions.xml'. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
返回頭,再去看教學視頻,發現那個講師傻乎乎的去把源碼放到服務器的linux環境下安裝maven,使用maven命令打包。這也太麻煩了,難道以後寫代碼就得提交代碼到服務器,再去打包了?
大兄弟,對這種傻乎乎的操作Say No!
摸爬滾打的半天,找到了上面提到的大佬的文章,雖然排版一般般,但是內容點醒了我。
下面開始我的操作。
第一步
因爲我的代碼是一個項目下的module,那麼配置一下這個module的pom文件,主要着重關注build部分內容吧
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>guangzhi</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<targetPath>${project.build.directory}/classes</targetPath>
<includes>
<include>**/*</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
大致內容就是指定了一下main方法和配置文件的位置。
第二步
剩下去配置run的maven命令。
第三步
點擊去之後,新建一個maven
第四步
然後就是配置你需要的內容了
maven打包命令是:clean assembly:assembly -Dcheckstyle.skip=true
注意,這裏不帶mvn。
這裏的**-Dcheckstyle.skip=true** 是爲了跳過checkstyle會檢查導致的失敗。
配置完成,點擊下面的ok就能保存成功了。
第五步
接下來運行我們剛剛配置的maven命令,使用快捷鍵 alt + shift +F10,IDEA會自動選中我們剛纔編輯的maven命令名字,直接回車,就可以開始編譯了。如果沒有選中,鼠標點一下也可以的。
第六步
打包好的jar包在對應的module下有個target目錄,目錄下有個jar-with-dependencies.jar字樣的包,就是我們最後需要跑在flink上的包了
第七步
使用提交命令,運行你的代碼
簡單說一下提交命令,在flink代碼的主函數中,我們會定義一個args,與這個類似
./flink run -c com.guangzhi.stream.ProcessData /opt/dsssanaly-1.6.1-jar-with-dependencies.jar --input-topic test --bootstrap.servers 192.168.30.119:9092 --zookeeper.connect 192.168.30.111:2181 --group.id myconsumer1 --output-topic test4
解釋一下對應的內容
-c com.guangzhi.stream.ProcessData 是我們在idea中調試程序運行的主方法的類文件,可以在idea中使用 Ctrl + Alt + Shift + C快捷鍵獲取到,或者 右鍵這個類文件,點擊 copy reference 拿到
-input-topic test7 是我們作爲消費者拿到kafka數據的topic
--bootstrap.servers 服務器ip:9092 是我們的Kafka的brokerIP和端口
--zookeeper.connect 服務器ip:2181 是我們的kafka鏈接zookeeper集羣配置
--group.id 可以隨意,影響不大
--output-topic test4 是我們將結果輸出的topic
剩下就可以去可視化頁面查看運行情況了。
再次感謝大佬幫助,沒有開頭提到的文章,還真困惑一段時間呢。