Scala - Tips
1- 运行scala命令,提示报错
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_HOME%\bin;%SCALA_HOME%\lib\dt.jar;%SCALA_HOME%\lib\tools.jar.;
注意:"变量值"最前面的 .; 不要漏掉。最后单击确定即可。
2- 在Win7 64bit系统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命令行下,编辑大块代码
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 - Tips的更多相关文章
- Scala的几个小tips
1. Main方法只能写在object而不是class里 2. Unit test只能针对class或者trait,不能给object做,解决方法,把object里面要测的方法拿出来放到trait里, ...
- gradle项目中如何支持java与scala混合使用?
之前写过一篇maven项目中java与scala如何混用,今天来看看gradle项目中如何达到同样的效果: 一.目录结构 基本上跟maven一样,tips:这一堆目录结构不用死记,后面会讲如何用gra ...
- 使用SBT构建Scala应用(转自git)
# 使用SBT构建Scala应用 ## SBT简介 SBT是Simple Build Tool的简称,如果读者使用过Maven,那么可以简单将SBT看做是Scala世界的Maven,虽然二者各有优劣, ...
- 【原】SBT构建Scala应用
[转帖] 原文地址:https://github.com/CSUG/real_world_scala/blob/master/02_sbt.markdown 尊重版权,尊重他人劳动成果,转帖请注明原文 ...
- scala模式匹配与样例类
样本类:添加了case的类便是样本类.这种修饰符可以让Scala编译器自动为这个类添加一些语法上的便捷设定.如下: 1.添加与类名一致的工厂方法.也就是说,可以写成Var("x") ...
- 【Scala-ML】使用Scala构建机器学习工作流
引言 在这一小节中.我将介绍基于数据(函数式)的方法来构建数据应用.这里会介绍monadic设计来创建动态工作流,利用依赖注入这种高级函数式特性来构建轻便的计算工作流. 建模过程 在统计学和概率论中, ...
- idea+scala sdk + scala插件
0X01 前言 我的主语言是python,说起java,想起了大二(三年前)上课时教过,课程设计的时候曾经做过个俄罗斯方块,后面其他设计copy代码读懂代码(再后面的课设就用python了). 本次涉 ...
- 使用SBT构建Scala应用【转载】
使用SBT构建Scala应用 SBT简介 SBT是Simple Build Tool的简称,如果读者使用过Maven,那么可以简单将SBT看做是Scala世界的Maven,虽然二者各有优劣,但完成的工 ...
- Mac上MySQL忘记root密码且没有权限的处理办法&workbench的一些tips (转)
忘记Root密码肿么办 Mac上安装MySQL就不多说了,去mysql的官网上下载最新的mysql包以及workbench,先安装哪个影响都不大.如果你是第一次安装,在mysql安装完成之后,会弹出来 ...
随机推荐
- GUI学习之五——QPushbutton类学习笔记
QPushButton是QAbstractButton类下使用最多的子类,它的用法在上一章中基本讲完了,这里还总结了几个别的用法. 一.创建按钮 我们在前面所有的案例中创建按钮都是用这样的方式 win ...
- @ReequestParam
@RequestParam:传递参数,即将请求参数区数据映射到功能处理方法的参数上 eg. public String queryUserName(@RequestParam String usern ...
- 上传本地文件到github
第一步:创建新的仓库 勾选Initialize this repository with a README选项,自动创建REAMDE.md文件. 第二步: $ git config --global ...
- Ajax基本语法
案例代码: $(function(){ $('#send').click(function(){ $.ajax({ type: "GET", url: "test.jso ...
- python3 爬取搜狗微信的文章
目标地址:http://weixin.sogou.com/weixin? 这个地址是搜狗微信的文章搜索,可以搜索到微信的文章,而我们目标就是这些文章内容 这个url经过测试,当我们没登陆微信只能看到1 ...
- Day08 (黑客成长日记) 命名空间和作用域
Day08:命名空间和作用域: 1.命名空间: (1)内置命名空间(python解释器): 就是python解释器一旦启动就可以使用的名字储存在内置命名空间中: eg: len() print() a ...
- 京东Alpha平台开发笔记系列(二)
第一篇博文简单讲了一下京东Alpha平台与个人idea技能,本篇将讲解Alpha平台与个人开发需要的一些知识,下面开篇 ——>>> 上图就是京东Alpha技能平台的首页,Skill平 ...
- css 文本超出2行就隐藏并且显示省略号
overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-box-orient: vertical; -webk ...
- pdf流文件的展示、下载、打印;html转为pdf
背景:合同(后台返回pdf流文件)展示.下载.打印,基于angular4 场景区分: 1.checkout页面 —— post接口,入参为offering.shippingInfo.invoice等( ...
- 将preg_replace()改写为preg_replace_callback()
preg_replace()函数使用/e修饰符可能带来安全隐患,PHP5.5之后,该用法被抛弃使用,升级为preg_replace_callback().在新版本下运行老版本的代码,会出现错误,如: ...