Hadoop novice from entry to buried structures (3) for windows scala + idea + sbt installation

Hadoop novice from entry to buried structures (3) for windows scala + idea + sbt installation

Following the prequel hadoop completed structures, and will be developed with scala, but we are ubuntusever, no graphical interface development is not very friendly to us novices, so we try to write the code on the windows, send it back to the virtual machine run.

Installation scala

Scala enter the official website, you can see there are three methods of installation (but we still have to use development ide idea, please go to download their own idea)

  1. idea to install
  2. sbt installation
  3. Binary installation

Here choose to install with SBT,
Here Insert Picture DescriptionSBT as something similar to a maven, specifically Zuosha I do not know, when the project build tool similar. . . . probably. . .
Here Insert Picture DescriptionHere is a very depressing place. . . Download speed is very unresponsive. . . Even with the Baidu network disk speed download and offline microdisk is also very unresponsive, I do not want to download, and I already exist on the network drive the following address

Links: https://pan.baidu.com/s/1C7pclMtUxUvK02vGo-sPdA extraction code: swak

Once downloaded, open and install.

After installation is complete, but also because of speed reasons, we use a mirror to download the country.

In the installation directory, / conf below sbtconfig.txt, open and edit, add the following

-Dsbt.global.base="E:/Program Files (x86)/sbt/.sbt"
-Dsbt.repository.config="E:/Program Files (x86)/sbt/properties"
-Dfile.encoding=UTF8
-Dsbt.boot.directory="E:/Program Files (x86)/sbt/sbt-repository/boot/"
-Dsbt.ivy.home="E:/Program Files (x86)/sbt/sbt-repository/"
-Dsbt.override.build.repos=true

E:/Program Files (x86)/sbtIs my installation path, we looked at the change note must be enclosed in double quotes, my directory has spaces existence, without the double quotes will be reported can not find the main class Files, this place I checked a lot I did not found until with the idea when input configuration, and found a space directly for the trip, and found , and then create a directory in the installation propertiesfile, content

[repositories]
local
alirepo1:https://maven.aliyun.com/repository/central
alirepo2:https://maven.aliyun.com/repository/jcenter
alirepo3:https://maven.aliyun.com/repository/public
huaweicloud-maven: https://repo.huaweicloud.com/repository/maven/
huaweicloud-ivy: https://repo.huaweicloud.com/repository/ivy/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
maven-central: https://repo1.maven.org/maven2/

In other source to pay attention here, stars based on individual tests. . . I do not know is not the case. . . If not the last line, the speed is very slow. But does not address to download from the last row. The above configuration Ali and Huawei's source of origin.

这个时候,找一个空目录,输入sbt,并输入c,在此环境下创建项目文件,正常的话会出现一行正在加载类的文字,具体是什么忘记了。如果源配置正常,大约半分钟到一分钟左右就会开始飞速下载,下载完成后,会出现等待输入的标识,如下图
Here Insert Picture Description这样就算sbt安装成功了,如果有项目文件则可以输入run进行运行。我们开发不可能用记事本开发,还是用ide开发,idea已经把sbt整合进去了,所以我们只要用idea进行开发就行了。

IDEA插件安装

正常的idea插件安装可以在主界面,点击Configure->Plugins

Here Insert Picture Description并搜索scala,(也可以在项目设置里面找)
Here Insert Picture Description这里又有一个坑点。。。我这里莫名连不上那边的服务器,于是我们去官网下载到本地安装,这个时候要先看自己idea的版本,根据版本去下载,我是2019.3,所以下载2019.3.23
Here Insert Picture Description这里虽然也比较慢,但是至少还能下,这里可以考虑用百度网盘离线下载等功能。
下载完成后,选择自己刚刚下载的压缩包,并重启idea就可以了。
Here Insert Picture Description

项目配置

idea的sbt的配置是独立于本机的配置的,需要重新配过。在主界面,点击Configure->Setiing,
找到sbt->vm parameters,输入之前在sbtconfig.txt里面的内容,然后ok就可以了。
Here Insert Picture Description

项目启动

Create New Project-> scala -> sbt
Here Insert Picture Description填写相关项目信息
Here Insert Picture Description创建完成之后,经过构建,项目目录如下

Here Insert Picture Description我们主要编程在src下,main/scala就是我们平常写代码的地方,test/scala是测试目录,我们可以在这两个地方其中一个地方进行代码的编写,一般还是建议在main/scala,目前还没发现有什么区别。在上述两个地方其中之一,右键NEW->Scala Class,创建一个Object
Here Insert Picture Description
输入文件名之后,选择Object,注意此处要选Object,这是和java不同的地方。

Here Insert Picture Description
以我的为例,输入代码

object test{
  def main(args: Array[String]) {
    println("Hello, SBT")
  }
 
}

Here Insert Picture Description

和java一样,object名和文件名必须相同。随后,右键运行
Here Insert Picture Description

非sbt用法

这里也简要介绍一下非sbt的运行方法,在scala官网下载windows二进制文件后,进行安装,安装完成后,做一遍idea的插件安装。不同的是不需要配置别的,直接创建新项目的时候选择idea就行,然后编好代码就可以右键运行,这个比sbt容易得多,不过sbt也有sbt的好处。但是这样子会比较快。
Here Insert Picture Description

题外话

本人有强迫症,在sbt开始的时候,会有windows拷贝,把一些文件拷贝到User/.sbt下,我也不知道这些会占用多大,当时粗略的看了一下,没下载东西的时候50M+,本着怀疑他会随库变多而变大的猜想,而本人的C盘也不太够。所以果断研究了一下,发现在sbt/bin下的sbt.bat的503行左右,有一个拷贝命令,但是目前没有看到这个有什么用,所以我注释了他。如图所示,现在还没发现有什么问题。

Here Insert Picture Description

总结

scala的环境安装弄了我一天,主要是

  1. Fans of the problem
    can not find the main class Files
    Solution: modify path sbtconfig.txt in question and, if space in double quotation marks.
        I think a lot of this place, I thought it was kind of java can not find Files, crunching several hours of java, when tested later in the idea which found the answer. In simple terms this place, read a lot of underlying things, even the bat file read it again, but also changed the .jar file
  2. Various Suman
    including sbt body slow download, idea plugin download is slow, slow sbt source
    to solve: the first two Baidu cloud disk or download the offline and so slowly, slow sbt source, for a lot of sources, found that the above configuration is the most Suitable.
  3. Obsessive-compulsive disorder .sbt folder
    solve: Note contents of the specified

I particularly want to spray scala, I may still be too dishes.

Published 16 original articles · won praise 2 · Views 3591

Guess you like

Origin blog.csdn.net/weixin_42056422/article/details/104590464