1- 运行scala命令,提示报错

问题现象:
在Windows7系统中安装scala后(直接安装MSI包,或者解压zip包添加环境变量的方式),执行scala命令报错,但可以执行scala -version
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\guowli>scala
Welcome to Scala 2.12.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_101).
Type in expressions for evaluation. Or try :help. scala> java.lang.NullPointerException
at java.util.Arrays.sort(Arrays.java:1438)
at scala.tools.nsc.classpath.JFileDirectoryLookup.listChildren(DirectoryClassPath.scala:113)
at scala.tools.nsc.classpath.JFileDirectoryLookup.listChildren$(DirectoryClassPath.scala:97)
at scala.tools.nsc.classpath.DirectoryClassPath.listChildren(DirectoryClassPath.scala:202)
at scala.tools.nsc.classpath.DirectoryClassPath.listChildren(DirectoryClassPath.scala:202)
at scala.tools.nsc.classpath.DirectoryLookup.list(DirectoryClassPath.scala:73)
at scala.tools.nsc.classpath.DirectoryLookup.list$(DirectoryClassPath.scala:69)
at scala.tools.nsc.classpath.DirectoryClassPath.list(DirectoryClassPath.scala:202)
at scala.tools.nsc.classpath.AggregateClassPath.$anonfun$list$1(AggregateClassPath.scala:76)
at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:234)
at scala.collection.Iterator.foreach(Iterator.scala:929)
at scala.collection.Iterator.foreach$(Iterator.scala:929)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1417)
at scala.collection.IterableLike.foreach(IterableLike.scala:71)
at scala.collection.IterableLike.foreach$(IterableLike.scala:70)
at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
at scala.collection.TraversableLike.map(TraversableLike.scala:234)
at scala.collection.TraversableLike.map$(TraversableLike.scala:227)
at scala.collection.AbstractTraversable.map(Traversable.scala:104)
at scala.tools.nsc.classpath.AggregateClassPath.list(AggregateClassPath.scala:74)
at scala.tools.nsc.symtab.SymbolLoaders$PackageLoader.doComplete(SymbolLoaders.scala:271)
at scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.complete(SymbolLoaders.scala:220)
at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:1530)
at scala.reflect.internal.Mirrors$RootsBase.init(Mirrors.scala:225)
at scala.tools.nsc.Global.rootMirror$lzycompute(Global.scala:65)
at scala.tools.nsc.Global.rootMirror(Global.scala:63)
at scala.tools.nsc.Global.rootMirror(Global.scala:36)
at scala.reflect.internal.Definitions$DefinitionsClass.ObjectClass$lzycompute(Definitions.scala:267)
at scala.reflect.internal.Definitions$DefinitionsClass.ObjectClass(Definitions.scala:267)
at scala.reflect.internal.Definitions$DefinitionsClass.init(Definitions.scala:1422)
at scala.tools.nsc.Global$Run.<init>(Global.scala:1164)
at scala.tools.nsc.interpreter.IMain._initialize(IMain.scala:125)
at scala.tools.nsc.interpreter.IMain.initializeSynchronous(IMain.scala:147)
at scala.tools.nsc.interpreter.ILoop.$anonfun$process$11(ILoop.scala:1030)
at scala.tools.nsc.interpreter.ILoop.startup$1(ILoop.scala:1011)
at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:1049)
at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:82)
at scala.tools.nsc.MainGenericRunner.run$1(MainGenericRunner.scala:85)
at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:96)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:101)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala) C:\Users\guowli> C:\Users\guowli>scala -version
Scala code runner version 2.12.4 -- Copyright 2002-2017, LAMP/EPFL and Lightbend, Inc. C:\Users\guowli>
原因分析:
可以执行scala -version命令,说明scala的环境变量是正确的。
无法scala命令,可能是调用相关库失败,检查Java是否正确安装和Scala环境变量Classpath的配置
处理方法:
1- 检查java和javac的版本是否可用并一致
2- 检查环境变量
设置 Classpath 变量(也可能为CLASSPATH,不区分大小写):找到找到系统变量下的"Classpath",单击编辑,添加如下内容
;%SCALA_HOME%\bin;%SCALA_HOME%\lib\dt.jar;%SCALA_HOME%\lib\tools.jar.;

注意:"变量值"最前面的 .; 不要漏掉。最后单击确定即可。

2- 在Win7 64bit系统cmd命令行下运行sbt命令,提示报错

在Windows7 64bit系统中安装sbt(未重启系统)后,在cmd命令行下执行sbt命令报错
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\guowli>sbt
"C:\Users\guowli\.sbt\preloaded\org.scala-sbt\sbt\"1.0.2"\jars\sbt.jar"
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
Getting org.fusesource.jansi jansi 1.11 ... :: problems summary ::
:::: WARNINGS
module not found: org.fusesource.jansi#jansi;1.11 ==== local: tried C:\Users\guowli\.ivy2\local\org.fusesource.jansi\jansi\1.11\ivys\ivy.xml -- artifact org.fusesource.jansi#jansi;1.11!jansi.jar: C:\Users\guowli\.ivy2\local\org.fusesource.jansi\jansi\1.11\jars\jansi.jar ==== local-preloaded-ivy: tried file:/C:/Users/guowli/.sbt/preloaded/org.fusesource.jansi/jansi/1.11/ivys/ivy.xml ==== local-preloaded: tried file:/C:/Users/guowli/.sbt/preloaded/org/fusesource/jansi/jansi/1.11/jansi-1.11.pom -- artifact org.fusesource.jansi#jansi;1.11!jansi.jar: file:/C:/Users/guowli/.sbt/preloaded/org/fusesource/jansi/jansi/1.11/jansi-1.11.jar ==== Maven Central: tried https://repo1.maven.org/maven2/org/fusesource/jansi/jansi/1.11/jansi-1.11.pom -- artifact org.fusesource.jansi#jansi;1.11!jansi.jar: https://repo1.maven.org/maven2/org/fusesource/jansi/jansi/1.11/jansi-1.11.jar ==== sbt-maven-releases: tried https://repo.scala-sbt.org/scalasbt/maven-releases/org/fusesource/jansi/jansi/1.11/jansi-1.11.pom -- artifact org.fusesource.jansi#jansi;1.11!jansi.jar: https://repo.scala-sbt.org/scalasbt/maven-releases/org/fusesource/jansi/jansi/1.11/jansi-1.11.jar ==== sbt-maven-snapshots: tried https://repo.scala-sbt.org/scalasbt/maven-snapshots/org/fusesource/jansi/jansi/1.11/jansi-1.11.pom -- artifact org.fusesource.jansi#jansi;1.11!jansi.jar: https://repo.scala-sbt.org/scalasbt/maven-snapshots/org/fusesource/jansi/jansi/1.11/jansi-1.11.jar ==== typesafe-ivy-releases: tried https://repo.typesafe.com/typesafe/ivy-releases/org.fusesource.jansi/jansi/1.11/ivys/ivy.xml ==== sbt-ivy-snapshots: tried https://repo.scala-sbt.org/scalasbt/ivy-snapshots/org.fusesource.jansi/jansi/1.11/ivys/ivy.xml :::::::::::::::::::::::::::::::::::::::::::::: :: UNRESOLVED DEPENDENCIES :: :::::::::::::::::::::::::::::::::::::::::::::: :: org.fusesource.jansi#jansi;1.11: not found :::::::::::::::::::::::::::::::::::::::::::::: :::: ERRORS
Server access Error: Connection timed out: connect url=https://repo1.maven.org/maven2/org/fusesource/jansi/jansi
/1.11/jansi-1.11.pom Server access Error: Connection timed out: connect url=https://repo1.maven.org/maven2/org/fusesource/jansi/jansi
/1.11/jansi-1.11.jar Server access Error: Connection timed out: connect url=https://repo.scala-sbt.org/scalasbt/maven-releases/org/fu
sesource/jansi/jansi/1.11/jansi-1.11.pom Server access Error: Connection timed out: connect url=https://repo.scala-sbt.org/scalasbt/maven-releases/org/fu
sesource/jansi/jansi/1.11/jansi-1.11.jar Server access Error: Connection timed out: connect url=https://repo.scala-sbt.org/scalasbt/maven-snapshots/org/f
usesource/jansi/jansi/1.11/jansi-1.11.pom Server access Error: Connection timed out: connect url=https://repo.scala-sbt.org/scalasbt/maven-snapshots/org/f
usesource/jansi/jansi/1.11/jansi-1.11.jar Server access Error: Connection timed out: connect url=https://repo.typesafe.com/typesafe/ivy-releases/org.fuses
ource.jansi/jansi/1.11/ivys/ivy.xml Server access Error: Connection timed out: connect url=https://repo.scala-sbt.org/scalasbt/ivy-snapshots/org.fus
esource.jansi/jansi/1.11/ivys/ivy.xml :: USE VERBOSE OR DEBUG MESSAGE LEVEL FOR MORE DETAILS
unresolved dependency: org.fusesource.jansi#jansi;1.11: not found
Error during sbt execution: Error retrieving required libraries
(see C:\Users\guowli\.sbt\boot\update.log for complete log)
Error: Could not retrieve jansi 1.11 C:\Users\guowli>
原因分析:
网络原因的导致无法获得依赖包
处理方法:
  • 设置可用的repo或代理。
  • 在用户目录下创建.sbt目录,放一个repositories文件
  • 在用户的~/.sbt目录和安装目录,例如:“C:\Program Files (x86)\sbt\conf”
guowli@5CG450158J MINGW64 ~/.sbt
$ ll
total 17
drwxr-xr-x 1 guowli 1049089 0 Nov 2 11:29 1.0/
drwxr-xr-x 1 guowli 1049089 0 Nov 2 13:38 boot/
drwxr-xr-x 1 guowli 1049089 0 Oct 26 10:55 preloaded/
-rw-r--r-- 1 guowli 1049089 880 Nov 2 13:29 repositories
-rw-r--r-- 1 guowli 1049089 253 Nov 2 13:30 sbtconfig.txt guowli@5CG450158J MINGW64 ~/.sbt
$ cat repositories
[repositories]
local
maven-repo2-ivy-releases: http://repo2.maven.org/maven2/, , [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
maven-repo2: http://repo2.maven.org/maven2/
maven-central-ivy-releases: http://repo1.maven.org/maven2/, , [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
maven-central: http://repo1.maven.org/maven2/
sbt-releases-repo: http://repo.typesafe.com/typesafe/ivy-releases/, , [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
sbt-plugins-repo: http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/, , [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
guowli@5CG450158J MINGW64 ~/.sbt
$ guowli@5CG450158J MINGW64 ~/.sbt
$ cat sbtconfig.txt
# Set the java args to high -Xmx512M -XX:MaxPermSize=256m -XX:ReservedCodeCacheSize=128m # Set the extra SBT options -Dsbt.log.format=true -Dhttp.proxySet=true -Dhttp.proxyHost=10.144.1.10 -Dhttp.proxyPort=8080 -Dsbt.override.build.repos=true
guowli@5CG450158J MINGW64 ~/.sbt
$

参考信息:

3- 在REPL命令行下,编辑大块代码

示例: 利用“:paste”选项
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\guowli>scala
Welcome to Scala 2.12.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_101).
Type in expressions for evaluation. Or try :help. scala> :paste
// Entering paste mode (ctrl-D to finish) def qSort(x: List[Int]): List[Int] = {
if (x.length <= 2) x
else qSort(x.filter(x.head > _)) ++
x.filter(x.head == _) ++
qSort(x.filter(x.head < _))
} // Exiting paste mode, now interpreting. qSort: (x: List[Int])List[Int] scala> qSort(List(6, 4, 5, 3, 1, 2, 9, 8, 0, 7))
res0: List[Int] = List(0, 1, 2, 3, 4, 5, 6, 8, 7, 9) scala>

4- main方法

对于一个Scala应用程序而言,必须包含main方法。
如果没有包含main方法,就不能使用scalac命令进行编译,而是直接使用scala命令运行代码。
 
 

Scala - Tips的更多相关文章

  1. Scala的几个小tips

    1. Main方法只能写在object而不是class里 2. Unit test只能针对class或者trait,不能给object做,解决方法,把object里面要测的方法拿出来放到trait里, ...

  2. gradle项目中如何支持java与scala混合使用?

    之前写过一篇maven项目中java与scala如何混用,今天来看看gradle项目中如何达到同样的效果: 一.目录结构 基本上跟maven一样,tips:这一堆目录结构不用死记,后面会讲如何用gra ...

  3. 使用SBT构建Scala应用(转自git)

    # 使用SBT构建Scala应用 ## SBT简介 SBT是Simple Build Tool的简称,如果读者使用过Maven,那么可以简单将SBT看做是Scala世界的Maven,虽然二者各有优劣, ...

  4. 【原】SBT构建Scala应用

    [转帖] 原文地址:https://github.com/CSUG/real_world_scala/blob/master/02_sbt.markdown 尊重版权,尊重他人劳动成果,转帖请注明原文 ...

  5. scala模式匹配与样例类

    样本类:添加了case的类便是样本类.这种修饰符可以让Scala编译器自动为这个类添加一些语法上的便捷设定.如下: 1.添加与类名一致的工厂方法.也就是说,可以写成Var("x") ...

  6. 【Scala-ML】使用Scala构建机器学习工作流

    引言 在这一小节中.我将介绍基于数据(函数式)的方法来构建数据应用.这里会介绍monadic设计来创建动态工作流,利用依赖注入这种高级函数式特性来构建轻便的计算工作流. 建模过程 在统计学和概率论中, ...

  7. idea+scala sdk + scala插件

    0X01 前言 我的主语言是python,说起java,想起了大二(三年前)上课时教过,课程设计的时候曾经做过个俄罗斯方块,后面其他设计copy代码读懂代码(再后面的课设就用python了). 本次涉 ...

  8. 使用SBT构建Scala应用【转载】

    使用SBT构建Scala应用 SBT简介 SBT是Simple Build Tool的简称,如果读者使用过Maven,那么可以简单将SBT看做是Scala世界的Maven,虽然二者各有优劣,但完成的工 ...

  9. Mac上MySQL忘记root密码且没有权限的处理办法&workbench的一些tips (转)

    忘记Root密码肿么办 Mac上安装MySQL就不多说了,去mysql的官网上下载最新的mysql包以及workbench,先安装哪个影响都不大.如果你是第一次安装,在mysql安装完成之后,会弹出来 ...

随机推荐

  1. Posche Piwis 3 Original and Clone – What’s the difference

    Category : Car Diagnostic Tools What’s the difference between Porsche Tester Piwis III original and ...

  2. BZOJ1270或洛谷1107 [BJWC2008]雷涛的小猫

    BZOJ原题链接 洛谷原题链接 \(DP\)水题. 定义\(f[i][j]\)表示小猫在高度\(i\),位于第\(j\)棵树时最多能吃到的柿子的数量.分为直接往下跳和跳到另一棵树两个决策. 那么很容易 ...

  3. EasyPR源码剖析(5):车牌定位之偏斜扭转

    一.简介 通过颜色定位和Sobel算子定位可以计算出一个个的矩形区域,这些区域都是潜在车牌区域,但是在进行SVM判别是否是车牌之前,还需要进行一定的处理.主要是考虑到以下几个问题: 1.定位区域存在一 ...

  4. 合适IT人的健身技巧

    合适IT人的健身技巧: 健身益寿生活十条 虽然遗传学家说人的平均寿命可长达120岁,但本世纪人的寿命远远达不到这个数字^有鉴于此,国外一批医生.心理学家和营养学家制定了健身益寿生活10条准则,认为如能 ...

  5. 浅谈React数据流管理

    引言:为什么数据流管理如此重要?react的核心思想就是:UI=render(data),data就是我们说的数据流,render是react提供的纯函数,所以用户界面的展示完全取决于数据层.这篇文章 ...

  6. web页面font-family显示

    font-family属性很简单,直接写在css或style样式中即可. 如: font-family: "Microsoft YaHei"; 但是如果希望电脑能正确的显示我们设置 ...

  7. 20155326《网络对抗》Web安全基础实践

    20155326<网络对抗>Web安全基础实践 实验后回答的问题 SQL注入攻击原理,如何防御? 原理:SQL注入攻击指的是在Web应用对后台数据库查询语句处理存在的安全漏洞,通过构建特殊 ...

  8. JAVA RSA非对称加密详解[转载]

    一.概述1.RSA是基于大数因子分解难题.目前各种主流计算机语言都支持RSA算法的实现2.java6支持RSA算法3.RSA算法可以用于数据加密和数字签名4.RSA算法相对于DES/AES等对称加密算 ...

  9. drawable内存管理

    图片对象: drawable bitmap etc.图片对象在Android上该缓存吗?什么时候缓存?怎么缓存?缓存后使用时怎么取出?怎么销毁?什么时候销毁? bitmap对象(new出来的) :需要 ...

  10. [XAF] Llamachant Framework Modules

    Llamachant Framework Modules 最近更新 2018-08-22 *变更:我们从所需的模块列表中删除了审计跟踪模块.如果要在应用程序中使用Audit Trail功能,请将Aud ...