maven scala idea 步驟_scala

來源:互聯網
上載者:User

 首先在idea中new->project, 然後如圖:


之後步驟如下:


之後點擊finish。

在src/main/scala/wr路徑下建立一個scala檔案WordCount.scala,代碼如下:

package wrimport org.apache.spark.{SparkConf, SparkContext}object WordCount {  def main(args: Array[String]) {//    if (args.length < 1) {//      System.err.println("Usage: <file>")//      System.exit(1)//    }    val conf = new SparkConf().setAppName("wordCount").setMaster("local")    val sc = new SparkContext(conf)    val line = sc.textFile("/user/root/test")    line.flatMap(_.split(" ")).map((_, 1)).reduceByKey(_+_).collect().foreach(println)    sc.stop()  }}
在原始pom.xml的基礎上更改scala.version的值,改成idea中scala SDK版本。之後刪除有關Junit的配置行,同時刪除src檔案並排的test檔案夾,(因為test用處不大,但是有可能因為版本問題出錯,因此在此處我選擇刪除)同時增加下面兩個配置。(這裡適用於WordCount)如果是複雜的,則需要在增加更多配置,在這裡省略

<plugin>          <groupId>org.apache.maven.plugins</groupId>          <artifactId>maven-jar-plugin</artifactId>          <configuration>            <archive>              <manifest>                <mainClass>wr.WordCount</mainClass>              </manifest>            </archive>          </configuration>        </plugin>
 <dependency>      <groupId>org.apache.spark</groupId>      <artifactId>spark-core_2.11</artifactId>      <version>2.2.0</version>    </dependency>
之後在project Structure中的Artifacts中進行添加

之後點擊apply之後點擊OK。打包完成。

在功能表列的build中點擊下圖按鈕。之後點擊build。最後在maven projects中的Lifecycle中選擇package,進行打包即可。



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.