scala安装使用教程_一篇搞定!

1、Scala高级语言

1.1 Scala简介

Scala是一门多范式(multi-paradigm)的编程语言,设计初衷是要集成面向对象编程和函数式编程的各种特性。 Scala运行在Java虚拟机上,并兼容现有的Java程序。 Scala源代码被编译成Java字节码,所以它可以运行于JVM之上,并可以调用现有的Java类库。 函数编程范式更适合用于Map/Reduce和大数据模型,着眼于函数本身,函数范式逻辑清晰、简单,非常适合用于处理基于不变数据的批量处理工作。 像Spark,kafka等都是采用Scala开发的,所以学习好大数据,掌握scala是必要的。Flink是带有scala的api支持。 官网:The Scala Programming Language

1.2 Scala安装部署

1、Scala需要Java运行时库,安装Scala需要首先安装JVM虚拟机,推荐安装JDK8。

2、进入Scala的官网The Scala Programming Language 下载页面,点击 All Previous Releases

3、选择 Scala 2.12.8

4、根据操作系统选择安装包

1.2.1 Windows下的环境配置

首先下载scala-2.12.8.msi 或 scala-2.12.8.zip都可以(二选一)。

1.msi是Windows下的安装文件,直接安装。一直下一步无需配置即可安装完成。
2.zip是压缩文件,只需要将压缩包中的文件解压到任意盘符即可

配置scala的环境变量:window左下角搜索环境变量--->编辑环境变量--->系统环境变量--->添加到path下面--->一步一步确定完即可。 scala环境变量不配置:记住对应scala安装位置。 然后新建“SCALA_HOME”环境变量,并将“%SCALA_HOME%\bin”追加到"%Path%"中。

1.2.2 Linux下的环境配置(选配)

在官方网址进入下载界面下载 scala-2.12.8.tgz

#通过命令tar -xvf scala-2.12.8.tar -C 解压到路径
​
#例如:
tar -xvf scala-2.12.8.tgz -C /usr/java
​
#在配置系统环境变量,将Scala
vi /etc/profile
#添加如下参数
export JAVA_HOME=Java安装目录
export PATH=$PATH:$JAVA_HOME/bin:/scala解压目录/bin
#例如:
export JAVA_HOME=/usr/java/jdk1.8.0_251
export PATH=$PATH:$JAVA_HOME/bin:/usr/local/scala-2.12.8/bin
#保存退出后重新加载
source /etc/profile
1.3 Scala解释器

Scala解释器也被称为REPL交互式编码环境,会快速编译scala代码为字节码,然后交给JVM来执行。

REPL:Read(取值)-> Evaluation(求值)-> Print(打印)-> Loop(循环)。其特点如下:

# 1.计算表达式:在"scala>"命令行内,键入scala代码,解释器会直接返回结果给你。如果你没有指定变量来存放这个值,那么值默认的名称为res,而且会显示结果的数据类型,比如Int、Double、String等等。
​
例如,输入:1 + 1,会看到
res0: Int = 2
# 2.内置变量:在后面可以继续使用res这个变量,以及它存放的值。
​
例如,2.0 * res0,返回
res1: Double = 4.0
例如,"Hi, " + res0,返回
res2: String = Hi, 2
​
# 3.自动补全:在scala>命令行内,可以使用Tab键进行自动补全。

在Windows下使用cmd命令进入DOS中,然后输入“scala”进入到REPL。

请编写你的第一条scala代码:

println("hello world")
1.4 IDEA集成Scala开发环境配置

目前Scala的开发工具主要有两种:Eclipse和IDEA,这两个开发工具都有相应的Scala插件,如果使用Eclipse,直接到Scala官网下载即可Download Scala IDE for Eclipse - Scala IDE for Eclipse。

由于IDEA的Scala插件更优秀,大多数Scala程序员都选择IDEA,可以到Download IntelliJ IDEA – The Leading Java and Kotlin IDE 下载社区免费版,点击下一步安装即可。

1.IDEA在线安装Scala插件 打开IDEA--->左上脚File--->Settings--->选中Plugins--->选择MarketPlace--->搜索Scala--->点击绿色的Install按钮--->等待联网下载安装--->安装完成重启IDEA。 如果再MarketPlace搜索不到Scala,则选择使用离线方式安装Scala插件,即参考"2.IDEA离线安装Scala插件(可选)"。

2.IDEA离线安装Scala插件(可选)

因为IDEA的插件下载网站是国外网站,所以建议在线下载后离线安装。建议通过IDEA插件网站进行下载。

 插件网址:JetBrains Marketplace

打开IDEA--->左上脚File--->Settings--->选中Plugins--->选中此轮状设置图标--->选择Install pulgin from disk... --->选择已经下载的插件压缩包即可--->选择restart IDEA。

安装Maven Maven是一个企业级Java项目的依赖和构建管理工具。 将maven安装包解压到某一个安装目录--->配置Maven的环境变量--->配置conf/settings.xml--->如果配置环境变量:测试是否安装好(进入cmd--->mvn) --->如果没有配置环境变量:测试是否安装好(进入cmd,走到maven解压目录下的bin目录--->执行./mvn) 。 关于settings.xml配置如下:

  • 修改如下配置中的第55行,将/opt/mavenrepository/替换成已经创建一个目录即可。

  • 添加如下配置中的159-164(含)这一段配置到你你的配置文件中的159行位置即可。

<?xml version="1.0" encoding="UTF-8"?>
​
<!--
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.
-->
​
<!--
| This is the configuration file for Maven. It can be specified at two levels:
|
|  1. User Level. This settings.xml file provides configuration for a single user,
|                 and is normally provided in ${user.home}/.m2/settings.xml.
|
|                 NOTE: This location can be overridden with the CLI option:
|
|                 -s /path/to/user/settings.xml
|
|  2. Global Level. This settings.xml file provides configuration for all Maven
|                 users on a machine (assuming they're all using the same Maven
|                 installation). It's normally provided in
|                 ${maven.conf}/settings.xml.
|
|                 NOTE: This location can be overridden with the CLI option:
|
|                 -gs /path/to/global/settings.xml
|
| The sections in this sample file are intended to give you a running start at
| getting the most out of your Maven installation. Where appropriate, the default
| values (values used when the setting is not specified) are provided.
|
|-->
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <!-- localRepository
  | The path to the local repository maven will use to store artifacts.
  |
  | Default: ${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->
  <localRepository>/opt/mavenrepository/</localRepository>
  <!-- interactiveMode
  | This will determine whether maven prompts you when it needs input. If set to false,
  | maven will use a sensible default value, perhaps based on some other setting, for
  | the parameter in question.
  |
  | Default: true
  <interactiveMode>true</interactiveMode>
  -->
​
  <!-- offline
  | Determines whether maven should attempt to connect to the network when executing a build.
  | This will have an effect on artifact downloads, artifact deployment, and others.
  |
  | Default: false
  <offline>false</offline>
  -->
​
  <!-- pluginGroups
  | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
  | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
  | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
  |-->
  <pluginGroups>
  <!-- pluginGroup
  | Specifies a further group identifier to use for plugin lookup.
  <pluginGroup>com.your.plugins</pluginGroup>
  -->
</pluginGroups>
​
  <!-- proxies
  | This is a list of proxies which can be used on this machine to connect to the network.
  | Unless otherwise specified (by system property or command-line switch), the first proxy
  | specification in this list marked as active will be used.
  |-->
  <proxies>
  <!-- proxy
  | Specification for one proxy, to be used in connecting to the network.
  |
  <proxy>
  <id>optional</id>
  <active>true</active>
  <protocol>http</protocol>
  <username>proxyuser</username>
  <password>proxypass</password>
  <host>proxy.host.net</host>
  <port>80</port>
  <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
  -->
</proxies>
​
  <!-- servers
  | This is a list of authentication profiles, keyed by the server-id used within the system.
  | Authentication profiles can be used whenever maven must make a connection to a remote server.
  |-->
  <servers>
  <!-- server
  | Specifies the authentication information to use when connecting to a particular server, identified by
  | a unique name within the system (referred to by the 'id' attribute below).
  |
  | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
  |       used together.
  |
  <server>
  <id>deploymentRepo</id>
  <username>repouser</username>
  <password>repopwd</password>
</server>
  -->
​
  <!-- Another sample, using keys to authenticate.
  <server>
  <id>siteServer</id>
  <privateKey>/path/to/private/key</privateKey>
  <passphrase>optional; leave empty if not used.</passphrase>
</server>
  -->
</servers>
​
  <!-- mirrors
  | This is a list of mirrors to be used in downloading artifacts from remote repositories.
  |
  | It works like this: a POM may declare a repository to use in resolving certain artifacts.
  | However, this repository may have problems with heavy traffic at times, so people have mirrored
  | it to several places.
  |
  | That repository definition will have a unique id, so we can create a mirror reference for that
  | repository, to be used as an alternate download site. The mirror site will be the preferred
  | server for that repository.
  |-->
  <mirrors>
  <!-- mirror
  | Specifies a repository mirror site to use instead of a given repository. The repository that
  | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
  | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
  |
  <mirror>
  <id>mirrorId</id>
  <mirrorOf>repositoryId</mirrorOf>
  <name>Human Readable Name for this Mirror.</name>
  <url>http://my.repository.com/repo/path</url>
</mirror>
  -->
  <mirror>
  <id>alimaven</id>
  <name>aliyun maven</name>
  <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
  <mirrorOf>central</mirrorOf>        
</mirror>
</mirrors>
​
​
  <!-- profiles
  | This is a list of profiles which can be activated in a variety of ways, and which can modify
  | the build process. Profiles provided in the settings.xml are intended to provide local machine-
  | specific paths and repository locations which allow the build to work in the local environment.
  |
  | For example, if you have an integration testing plugin - like cactus - that needs to know where
  | your Tomcat instance is installed, you can provide a variable here such that the variable is
  | dereferenced during the build process to configure the cactus plugin.
  |
  | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
  | section of this document (settings.xml) - will be discussed later. Another way essentially
  | relies on the detection of a system property, either matching a particular value for the property,
  | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
  | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
  | Finally, the list of active profiles can be specified directly from the command line.
  |
  | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
  |       repositories, plugin repositories, and free-form properties to be used as configuration
  |       variables for plugins in the POM.
  |
  |-->
  <profiles>
  <!-- profile
  | Specifies a set of introductions to the build process, to be activated using one or more of the
  | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
  | or the command line, profiles have to have an ID that is unique.
  |
  | An encouraged best practice for profile identification is to use a consistent naming convention
  | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
  | This will make it more intuitive to understand what the set of introduced profiles is attempting
  | to accomplish, particularly when you only have a list of profile id's for debug.
  |
  | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
  <profile>
  <id>jdk-1.4</id>
​
  <activation>
  <jdk>1.4</jdk>
</activation>
​
  <repositories>
  <repository>
  <id>jdk14</id>
  <name>Repository for JDK 1.4 builds</name>
  <url>http://www.myhost.com/maven/jdk14</url>
  <layout>default</layout>
  <snapshotPolicy>always</snapshotPolicy>
</repository>
</repositories>
</profile>
  -->
​
  <!--
  | Here is another profile, activated by the system property 'target-env' with a value of 'dev',
  | which provides a specific path to the Tomcat instance. To use this, your plugin configuration
  | might hypothetically look like:
  |
  | ...
  | <plugin>
  |   <groupId>org.myco.myplugins</groupId>
  |   <artifactId>myplugin</artifactId>
  |
  |   <configuration>
  |     <tomcatLocation>${tomcatPath}</tomcatLocation>
  |   </configuration>
  | </plugin>
  | ...
  |
  | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
  |       anything, you could just leave off the <value/> inside the activation-property.
  |
  <profile>
  <id>env-dev</id>
​
  <activation>
  <property>
  <name>target-env</name>
  <value>dev</value>
</property>
</activation>
​
  <properties>
  <tomcatPath>/path/to/tomcat/instance</tomcatPath>
</properties>
</profile>
  -->
</profiles>
​
  <!-- activeProfiles
  | List of profiles that are active for all builds.
  |
  <activeProfiles>
  <activeProfile>alwaysActiveProfile</activeProfile>
  <activeProfile>anotherAlwaysActiveProfile</activeProfile>
</activeProfiles>
  -->
</settings>
​

测试是否可用,进入cmd中输入mvn即可。

IDEA整合Maven

  1. 打开IDEA--->左上脚File--->Settings--->搜索Maven--->选择Build tools下的Maven选项--->其它如下图

image.png

  1. 为以后的每一个新项目配置maven信息

image.png

左上脚搜索Maven--->选择Build tools下的Maven选项--->其它如下图

image.png

课上练习:请编写你的第一个Scala程序HelloWorld 打开IDEA--->点击左上脚File--->new--->new project--->如下图所示

image.png

image.png

我在this window展示项目如下

image.png

到此为止,maven类型的工程创建好。

IDEA整合ScalaSDK

1、hn-bigdata--->main--->new --->directory--->新建一个scala目录。 2、idea左上角File--->project structure..--->如下图所示

image.png

image.png

到此为止,我们创建hn-bigdata已经和scala SDK整合好。

创建Scala第一个代码 1、选择hn-bidata下的scala包--->右键--->new--->package--->创建com.qianfeng.scala的包 2、在scala包中创建Demo01_FirstScala--->代码如下

package com.qianfeng.scala
​
/**
* 第一个scala代码
*/
object Demo01_FirstScala {
  def main(args: Array[String]): Unit = {
    println("hello world!!!")
    val a = 1
    val b =  2
    println(a+b)
  }
}

右键运行上述代码即可。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/231351.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

解读Stable Video Diffusion:详细解读视频生成任务中的数据清理技术

Diffusion Models视频生成-博客汇总 前言:Stable Video Diffusion已经开源一周多了,技术报告《Stable Video Diffusion: Scaling Latent Video Diffusion Models to Large Datasets》对数据清洗的部分描述非常详细,虽然没有开源源代码,但是博主正在尝试复现其中的操作。这篇…

DSP处理器及其体系结构特点(您都用过哪些DSP?)

DSP处理器概述 数字信号处理器&#xff08;Digital Signal Processor&#xff0c;DSP&#xff09;是一种专门设计用于执行数字信号处理任务的微处理器类型。与通用微处理器&#xff08;如CPU&#xff09;相比&#xff0c;DSP处理器在处理数字信号时具有更高的性能和效率。 用途…

做抖店代发,新手如何定类目?五大类目优缺点分析!

我是电商珠珠 类目是店铺的方向&#xff0c;只有将店铺的定位确定好&#xff0c;才能超越大部分的同行。 我经常跟我的学生讲&#xff0c;选择类目的时候不能瞎选&#xff0c;要学会去分析市场&#xff0c;由于大部分的学员前期都是新手小白&#xff0c;所以我们这边会负责给…

二维数组附近遍历所有值

二维数组附近遍历所有值 假如以56点为中心&#xff0c;上下左右近距离遍历附近值&#xff0c;看代码&#xff0c;代码把思路写出来了&#xff0c;边界问题暂不处理。 #include<iostream> using namespace std;void FindNearPos(int (*int_arr)[10] , int p_row , int …

解决nuxt使用api代理报错: debug_1$6.Debug.extend is not a function

现象&#xff1a; 这个是使用了nuxt-proxy报的错&#xff0c;但是仅在生产环境才会报错&#xff0c;开发环境没有这个问题。 具体详情可见下面的github issues. nuxt proxy issue 解决办法&#xff1a; 改用代理中间件&#xff1a;nuxt-proxy-request 使用这个中间件的原因…

【工程实践】使用modelscope下载大模型文件

前言 Modelscope&#xff08;魔搭社区&#xff09;是阿里达摩院的一款开源模型平台&#xff0c;里面提供了很多的热门模型供使用体验&#xff0c;其中的模型文件可以通过git clone 快速下载。并且为模型提供了Notebook的快速开发体验&#xff0c;使用阿里云服务&#xff0c;不需…

uView框架的安装与Git管理

参考链接&#xff1a;Http请求 | uView - 多平台快速开发的UI框架 - uni-app UI框架 安装 打开我们项目的cmd进行下载&#xff1a; yarn add uview-ui 首先我们要确定&#xff0c;未下载前的文件目录以及下载后&#xff0c;是多了个文件目录node_modules 下载完成之后我们就…

Android之Binder原理剖析

一&#xff1a;Binder的全面介绍 binder的出现 George Hoffman当时任Be公司的工程师&#xff0c;他启动了一个名为OpenBinder 的项目&#xff0c;在Be公司被ParmSource公司收购后&#xff0c; OpenBinder 由Dinnie Hackborn继续开发&#xff0c;后来成为管理ParmOS6 Cobalt O…

GAN:WGAN-DIV

论文&#xff1a;https://arxiv.org/pdf/1712.01026.pdf 代码&#xff1a; 发表&#xff1a;2018 摘要 在计算机视觉的许多领域中&#xff0c;生成对抗性网络已经取得了巨大的成功&#xff0c;其中WGANs系列被认为是最先进的&#xff0c;主要是由于其理论贡献和竞争的定性表…

免费网页抓取工具大全【附下载和工具使用教程】

在当今信息爆炸的时代&#xff0c;获取准确而丰富的数据对于企业决策和个人研究至关重要。而网页抓取工具作为一种高效获取互联网数据的方式&#xff0c;正逐渐成为大家解决数据需求的得力助手。本文将深入探讨网页抓取工具的种类&#xff0c;并为大家提供简单实用的页面采集教…

FL Studio2024永久免费体验版下载

FL Studio中文绿色21版是一款无需要安装的汉化版本&#xff0c;它是一款非常专业的音频编辑软件&#xff0c;可以让你的音乐突破想象力的限制哦&#xff0c;FL Studio21中文版可以制作出不同音律的节奏&#xff0c;FL Studio内置众多电子合成音色&#xff0c;只Styrus可以让人激…

低多边形游戏风格3D模型纹理贴图

在线工具推荐&#xff1a; 3D数字孪生场景编辑器 - GLTF/GLB材质纹理编辑器 - 3D模型在线转换 - Three.js AI自动纹理开发包 - YOLO 虚幻合成数据生成器 - 三维模型预览图生成器 - 3D模型语义搜索引擎 当谈到游戏角色的3D模型风格时&#xff0c;有几种不同的风格&#xf…

5G+AI开花结果,助力智慧安检落地

“请带包的乘客过机安检&#xff01;”&#xff0c;深圳地铁、腾讯共同打造的5GAI智慧安检辅助系统亮相福田枢纽站&#xff0c;进一步解放了人力&#xff0c;提高安检效率&#xff0c;为交通安全保驾护航&#xff0c;让智慧出行成为现实。 传统的安检设备均为人工肉眼辨识&…

【Altera】Quartus II 软件怎么更改bank电压

前言 FPGA的bank电压要和物理设计相同&#xff0c;Quartus II 软件怎么更改bank电压&#xff1f; 步骤 启动 Pin Planner&#xff08;快捷方式&#xff1a;CTRL Shift N&#xff09;右键单击 Pin Planner 的背景&#xff0c;然后选择"显示 I/O bank"。右键…

小知识点——Servlet

Servlet 是什么&#xff1f; Java Servlet 是运行在 Web 服务器或应用服务器上的程序&#xff0c;它是作为来自 Web 浏览器或其他 HTTP 客户端的请求和 HTTP 服务器上的数据库或应用程序之间的中间层。使用 Servlet&#xff0c;您可以收集来自网页表单的用户输入&#xff0c;呈…

对python自动生成接口测试的示例讲解

在python中Template可以将字符串的格式固定下来&#xff0c;重复利用。 同一套测试框架为了可以复用&#xff0c;所以我们可以将用例部分做参数化&#xff0c;然后运用到各个项目中。 代码如下&#xff1a; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 2…

WordPress限制搜索关键词实现搜索黑名单

昨天有位站长问我能不能限制WordPress的搜索关键词&#xff0c;因为有人利用他的网站搜索色情词汇&#xff0c;本来正常搜索没有影响的&#xff0c;但是在部分网站中&#xff0c;搜索关键词产生的搜索页会被搜索引擎收录&#xff0c;实现推广功能。 WordPress的关键词搜索限制实…

谈谈对OOA、OOD、OOP理解

1 前言 按照开发阶段排序&#xff0c;有如下排序&#xff1a; OOA阶段&#xff1a;面向对象分析&#xff0c;此阶段领域建模&#xff0c;需求分析。OOD阶段&#xff1a;面向对象设计&#xff0c;此阶段输出系统概要设计、系统详细设计。OOP阶段&#xff1a;面向对象编程&#…

原码、反码、补码、大端、小端

原码、反码、补码 计算机中的整数有三种2进制表示方法&#xff0c;即原码、反码和补码。 三种表示方法均有符号位和数值位两部分&#xff0c;符号位都是用0表示“正”&#xff0c;用1表示“负”&#xff0c; 而数值位&#xff1a; 正数的原、反、补码都相同。负整数的三种表…

【PHP】php发送邮箱验证码格式美化,样式美化

效果展示&#xff1a; 格式美化前 格式美化后 代码 大多数框架都自带有封装好的发送email方法&#xff0c;就不多赘述&#xff0c;主要写格式&#xff1a; <? php// 验证码过期时间 $expire 120; // 发件人邮箱 $from_email xx163.com; // 收件人 $to_email to163.com…
最新文章