{"id":263,"date":"2023-04-11T09:30:58","date_gmt":"2023-04-11T01:30:58","guid":{"rendered":"https:\/\/yhsbj.cn\/?p=263"},"modified":"2023-04-11T09:32:42","modified_gmt":"2023-04-11T01:32:42","slug":"maven%e6%9e%84%e5%bb%baflink%e9%a1%b9%e7%9b%ae%e8%af%bb%e5%8f%96%e6%9c%ac%e5%9c%b0%e6%96%87%e4%bb%b6%e7%bb%9f%e8%ae%a1%e5%8d%95%e8%af%8d","status":"publish","type":"post","link":"https:\/\/yhsbj.cn\/index.php\/2023\/04\/11\/263\/","title":{"rendered":"maven\u6784\u5efaFlink\u9879\u76ee\u8bfb\u53d6\u672c\u5730\u6587\u4ef6\u7edf\u8ba1\u5355\u8bcd"},"content":{"rendered":"\n<p>0.\u5b89\u88c5maven\uff0c\u5e76\u521b\u5efa\u9879\u76ee<\/p>\n\n\n\n<p>1.Java\u4ee3\u7801<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">package com.test.maven;\n\nimport org.apache.flink.api.common.functions.FlatMapFunction;\nimport org.apache.flink.api.java.DataSet;\nimport org.apache.flink.api.java.ExecutionEnvironment;\nimport org.apache.flink.api.java.operators.AggregateOperator;\nimport org.apache.flink.api.java.operators.DataSource;\nimport org.apache.flink.api.java.operators.Operator;\nimport org.apache.flink.api.java.tuple.Tuple2;\nimport org.apache.flink.util.Collector;\n\npublic class App \n{\n    public static void main( String[] args )\n    {\n        try{\n            ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();\n            DataSource&lt;String> dataSource = env.readTextFile(\"E:\\\\hello.txt\");\n  \n            AggregateOperator&lt;Tuple2&lt;String, Integer>> dataSourceSum = dataSource.flatMap(new FlatMapFunction&lt;String, Tuple2&lt;String, Integer>>() {\n                @Override\n                public void flatMap(String value, Collector&lt;Tuple2&lt;String, Integer>> out) throws Exception {\n                    String[] words = value.split(\" \");\n                    for (String word : words) {\n                        out.collect(new Tuple2&lt;>(word, 1));\n                    }\n                }\n            }).groupBy(0).sum(1);\n            dataSourceSum.print(\"dataSourceSum: \");\n\n            env.execute();\n        }\n        catch(Exception e)\n        {\n        }\n    }\n}<\/pre>\n\n\n\n<p>2.pom.xml\u6dfb\u52a0flink\u4f9d\u8d56<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"xml\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;dependencies>\n    &lt;dependency>\n        &lt;groupId>org.apache.flink&lt;\/groupId>\n        &lt;artifactId>flink-streaming-java_${scala.version}&lt;\/artifactId>\n        &lt;version>${flink.version}&lt;\/version>\n    &lt;\/dependency>\n    &lt;dependency>\n        &lt;groupId>org.apache.flink&lt;\/groupId>\n        &lt;artifactId>flink-clients_${scala.version}&lt;\/artifactId>\n        &lt;version>${flink.version}&lt;\/version>\n    &lt;\/dependency>\n    &lt;dependency>\n        &lt;groupId>org.apache.flink&lt;\/groupId>\n        &lt;artifactId>flink-runtime-web_${scala.version}&lt;\/artifactId>\n        &lt;version>${flink.version}&lt;\/version>\n    &lt;\/dependency>\n&lt;\/dependencies><\/pre>\n\n\n\n<p>3.pom.xml\u6dfb\u52a0\u63d2\u4ef6\u6253\u5305jar\uff0cmainClass\u4fee\u6539\u4e3a\u5f53\u524d\u5de5\u7a0b\u7684\u7c7b<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"xml\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;build>\n    &lt;plugins>\n        &lt;plugin>\n            &lt;groupId>org.apache.maven.plugins&lt;\/groupId>\n            &lt;artifactId>maven-shade-plugin&lt;\/artifactId>\n            &lt;version>1.2.1&lt;\/version>\n            &lt;executions>\n                &lt;execution>\n                    &lt;phase>package&lt;\/phase>\n                    &lt;goals>\n                        &lt;goal>shade&lt;\/goal>\n                    &lt;\/goals>\n                    &lt;configuration>\n                        &lt;transformers>\n                            &lt;transformer implementation=\"org.apache.maven.plugins.shade.resource.ManifestResourceTransformer\">\n                                &lt;mainClass>com.test.maven.App&lt;\/mainClass>\n                            &lt;\/transformer>\n                        &lt;\/transformers>\n                    &lt;\/configuration>\n                &lt;\/execution>\n            &lt;\/executions>\n        &lt;\/plugin>\n    &lt;\/plugins>\n&lt;\/build><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" src=\"https:\/\/yhsbj.cn\/wp-content\/uploads\/2023\/04\/\u6355\u83b7-18-1024x609.png\" alt=\"\" class=\"wp-image-264\" width=\"584\" height=\"347\" srcset=\"https:\/\/yhsbj.cn\/wp-content\/uploads\/2023\/04\/\u6355\u83b7-18-1024x609.png 1024w, https:\/\/yhsbj.cn\/wp-content\/uploads\/2023\/04\/\u6355\u83b7-18-300x178.png 300w, https:\/\/yhsbj.cn\/wp-content\/uploads\/2023\/04\/\u6355\u83b7-18-768x457.png 768w, https:\/\/yhsbj.cn\/wp-content\/uploads\/2023\/04\/\u6355\u83b7-18-1536x913.png 1536w, https:\/\/yhsbj.cn\/wp-content\/uploads\/2023\/04\/\u6355\u83b7-18.png 1658w\" sizes=\"(max-width: 584px) 100vw, 584px\" \/><\/figure>\n\n\n\n<p>4.\u6253\u5f00cmd\u6267\u884cmvn install<\/p>\n\n\n\n<p>5.\u6253\u5f00Flink UI\uff0c\u7136\u540e\u52a0\u8f7djar<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" src=\"https:\/\/yhsbj.cn\/wp-content\/uploads\/2023\/04\/\u6355\u83b7-19-1024x328.png\" alt=\"\" class=\"wp-image-266\" width=\"631\" height=\"202\" srcset=\"https:\/\/yhsbj.cn\/wp-content\/uploads\/2023\/04\/\u6355\u83b7-19-1024x328.png 1024w, https:\/\/yhsbj.cn\/wp-content\/uploads\/2023\/04\/\u6355\u83b7-19-300x96.png 300w, https:\/\/yhsbj.cn\/wp-content\/uploads\/2023\/04\/\u6355\u83b7-19-768x246.png 768w, https:\/\/yhsbj.cn\/wp-content\/uploads\/2023\/04\/\u6355\u83b7-19-1536x492.png 1536w, https:\/\/yhsbj.cn\/wp-content\/uploads\/2023\/04\/\u6355\u83b7-19.png 1928w\" sizes=\"(max-width: 631px) 100vw, 631px\" \/><\/figure>\n\n\n\n<p>6.\u63d0\u4ea4\u8fd0\u884c<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" src=\"https:\/\/yhsbj.cn\/wp-content\/uploads\/2023\/04\/\u6355\u83b7-20-1024x423.png\" alt=\"\" class=\"wp-image-267\" width=\"542\" height=\"223\" srcset=\"https:\/\/yhsbj.cn\/wp-content\/uploads\/2023\/04\/\u6355\u83b7-20-1024x423.png 1024w, https:\/\/yhsbj.cn\/wp-content\/uploads\/2023\/04\/\u6355\u83b7-20-300x124.png 300w, https:\/\/yhsbj.cn\/wp-content\/uploads\/2023\/04\/\u6355\u83b7-20-768x317.png 768w, https:\/\/yhsbj.cn\/wp-content\/uploads\/2023\/04\/\u6355\u83b7-20-1536x635.png 1536w, https:\/\/yhsbj.cn\/wp-content\/uploads\/2023\/04\/\u6355\u83b7-20.png 1813w\" sizes=\"(max-width: 542px) 100vw, 542px\" \/><\/figure>\n\n\n\n<p>7.\u5728E\u76d8\u521b\u5efa\u4e00\u4e2a\u6587\u672c\u6587\u4ef6hello.txt\uff0c\u7136\u540e\u968f\u4fbf\u8f93\u5165\u4e00\u4e9b\u5b57\u6bcd\u5355\u8bcd\uff0c\u7528\u7a7a\u683c\u9694\u5f00<\/p>\n\n\n\n<p>8.\u6210\u529f\u540e\uff0c\u542f\u52a8Flink\u76842\u4e2a\u7a97\u53e3\u5176\u4e2d\u4e00\u4e2a\u4f1a\u51fa\u73b0\u7edf\u8ba1\u7684\u4fe1\u606f<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" src=\"https:\/\/yhsbj.cn\/wp-content\/uploads\/2023\/04\/\u6355\u83b7-21.png\" alt=\"\" class=\"wp-image-268\" width=\"393\" height=\"352\" srcset=\"https:\/\/yhsbj.cn\/wp-content\/uploads\/2023\/04\/\u6355\u83b7-21.png 636w, https:\/\/yhsbj.cn\/wp-content\/uploads\/2023\/04\/\u6355\u83b7-21-300x269.png 300w\" sizes=\"(max-width: 393px) 100vw, 393px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>0.\u5b89\u88c5maven\uff0c\u5e76\u521b\u5efa\u9879\u76ee 1.Java\u4ee3\u7801 2.pom.xml\u6dfb\u52a0flink\u4f9d\u8d56 3.pom.xml\u6dfb\u52a0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/yhsbj.cn\/index.php\/wp-json\/wp\/v2\/posts\/263"}],"collection":[{"href":"https:\/\/yhsbj.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yhsbj.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yhsbj.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yhsbj.cn\/index.php\/wp-json\/wp\/v2\/comments?post=263"}],"version-history":[{"count":3,"href":"https:\/\/yhsbj.cn\/index.php\/wp-json\/wp\/v2\/posts\/263\/revisions"}],"predecessor-version":[{"id":271,"href":"https:\/\/yhsbj.cn\/index.php\/wp-json\/wp\/v2\/posts\/263\/revisions\/271"}],"wp:attachment":[{"href":"https:\/\/yhsbj.cn\/index.php\/wp-json\/wp\/v2\/media?parent=263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yhsbj.cn\/index.php\/wp-json\/wp\/v2\/categories?post=263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yhsbj.cn\/index.php\/wp-json\/wp\/v2\/tags?post=263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}