《Scala入坑笔记》缘起 3天就搞了一个 hello world

简介: 有小伙伴向我咨询 play framework 的问题,我就想了解一下 play framework ,按照官方的文档,要使用 SBT 安装,就掉进了 SBT 的坑。第一坑:国外仓库太慢安装完成后,执行$ sbt命令后,提示:Java HotSpot(TM) 64-Bit Serve...

有小伙伴向我咨询 play framework 的问题,我就想了解一下 play framework ,按照官方的文档,要使用 SBT 安装,就掉进了 SBT 的坑。

第一坑:国外仓库太慢

安装完成后,执行

$ sbt
命令后,提示:

Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=384m; support was removed in 8.0
Getting org.scala-sbt sbt 0.13.15  (this may take some time)...
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/sbt/0.13.15/jars/sbt.jar ...
	[SUCCESSFUL ] org.scala-sbt#sbt;0.13.15!sbt.jar (22976ms)
downloading https://repo1.maven.org/maven2/org/scala-lang/scala-library/2.10.6/scala-library-2.10.6.jar ...
	[SUCCESSFUL ] org.scala-lang#scala-library;2.10.6!scala-library.jar (1553281ms)
然后就是漫长的等待!

第二坑:同时只能有一个 sbt 进程操作本地仓库

由于过程太慢,于是就打开新的终端窗口操作,结果不管执行 sbt 相关的什么命令都提示:

Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=384m; support was removed in 8.0
Waiting for lock on /Users/aven/.sbt/boot/sbt.boot.lock to be available...
原因是有多个sbt终端同时在运行,使得多个进程同时在访问.sbt.ivy.lock。
解决办法是:打开你的资源管理器,将你本机的java进程全部kill掉。

第三坑:配置使用国内仓库

既然是构架依赖管理工具,像Maven、yum之类的都可以添加或修改库的位置,于是:

vi ~/.sbt/repositories
添加以下内容:

[repositories]
#local
public: http://maven.aliyun.com/nexus/content/groups/public/
typesafe:http://dl.bintray.com/typesafe/ivy-releases/ , [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext], bootOnly
ivy-sbt-plugin:http://dl.bintray.com/sbt/sbt-plugin-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
sonatype-oss-releases

sonatype-oss-snapshots

第四坑:每次执行 sbt 相关命令都下载依赖包

网上也没见别人遇到这样的问题,我的怎么就这么奇葩呢?

经过很长一段时间的折腾,我日了,原来是上面  repositories 文件内容的原因,看到没:

#local

泥马,local 被注释了,所以每次都使用远程的!

就是由于这个原因,加上下载依赖实现是太慢,所以3天就搞了一个 hello world。

第五坑:依赖真不少

创建一个 hello world 项目,然后就是漫漫的等待。

new sbt/scala-seed.g8
[info] Resolving org.slf4j#slf4j-parent;1.7.20 ...
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/org/scala-sbt/sbt-giter8-resolver/sbt-giter8-resolver_2.10/0.1.3/sbt-giter8-resolver_2.10-0.1.3.jar ...
[info] 	[SUCCESSFUL ] org.scala-sbt.sbt-giter8-resolver#sbt-giter8-resolver_2.10;0.1.3!sbt-giter8-resolver_2.10.jar (378ms)
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/org/foundweekends/giter8/giter8_2.10/0.7.2/giter8_2.10-0.7.2.jar ...
[info] 	[SUCCESSFUL ] org.foundweekends.giter8#giter8_2.10;0.7.2!giter8_2.10.jar (449ms)
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/org/foundweekends/giter8/giter8-lib_2.10/0.7.2/giter8-lib_2.10-0.7.2.jar ...
[info] 	[SUCCESSFUL ] org.foundweekends.giter8#giter8-lib_2.10;0.7.2!giter8-lib_2.10.jar (593ms)
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/com/github/scopt/scopt_2.10/3.5.0/scopt_2.10-3.5.0.jar ...
[info] 	[SUCCESSFUL ] com.github.scopt#scopt_2.10;3.5.0!scopt_2.10.jar (280ms)
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/ch/qos/logback/logback-classic/1.1.7/logback-classic-1.1.7.jar ...
[info] 	[SUCCESSFUL ] ch.qos.logback#logback-classic;1.1.7!logback-classic.jar (575ms)
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/org/clapper/scalasti_2.10/2.1.2/scalasti_2.10-2.1.2.jar ...
[info] 	[SUCCESSFUL ] org.clapper#scalasti_2.10;2.1.2!scalasti_2.10.jar (251ms)
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/org/eclipse/jgit/org.eclipse.jgit.pgm/3.7.0.201502260915-r/org.eclipse.jgit.pgm-3.7.0.201502260915-r.jar ...
[info] 	[SUCCESSFUL ] org.eclipse.jgit#org.eclipse.jgit.pgm;3.7.0.201502260915-r!org.eclipse.jgit.pgm.jar (362ms)
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/commons-io/commons-io/2.4/commons-io-2.4.jar ...
[info] 	[SUCCESSFUL ] commons-io#commons-io;2.4!commons-io.jar (371ms)
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/org/codehaus/plexus/plexus-archiver/2.7.1/plexus-archiver-2.7.1.jar ...
[info] 	[SUCCESSFUL ] org.codehaus.plexus#plexus-archiver;2.7.1!plexus-archiver.jar (323ms)
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/org/clapper/grizzled-scala_2.10/3.1.0/grizzled-scala_2.10-3.1.0.jar ...
[info] 	[SUCCESSFUL ] org.clapper#grizzled-scala_2.10;3.1.0!grizzled-scala_2.10.jar (1142ms)
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/org/clapper/classutil_2.10/1.1.0/classutil_2.10-1.1.0.jar ...
[info] 	[SUCCESSFUL ] org.clapper#classutil_2.10;1.1.0!classutil_2.10.jar (765ms)
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/org/antlr/ST4/4.0.8/ST4-4.0.8.jar ...
[info] 	[SUCCESSFUL ] org.antlr#ST4;4.0.8!ST4.jar (959ms)
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/org/ow2/asm/asm/5.1/asm-5.1.jar ...
[info] 	[SUCCESSFUL ] org.ow2.asm#asm;5.1!asm.jar (505ms)
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/org/ow2/asm/asm-commons/5.1/asm-commons-5.1.jar ...
[info] 	[SUCCESSFUL ] org.ow2.asm#asm-commons;5.1!asm-commons.jar (677ms)
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/org/ow2/asm/asm-util/5.1/asm-util-5.1.jar ...
[info] 	[SUCCESSFUL ] org.ow2.asm#asm-util;5.1!asm-util.jar (809ms)
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/org/ow2/asm/asm-tree/5.1/asm-tree-5.1.jar ...
[info] 	[SUCCESSFUL ] org.ow2.asm#asm-tree;5.1!asm-tree.jar (1024ms)
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/org/antlr/antlr-runtime/3.5.2/antlr-runtime-3.5.2.jar ...
[info] 	[SUCCESSFUL ] org.antlr#antlr-runtime;3.5.2!antlr-runtime.jar (1680ms)
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/args4j/args4j/2.0.12/args4j-2.0.12.jar ...
[info] 	[SUCCESSFUL ] args4j#args4j;2.0.12!args4j.jar (798ms)
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/org/apache/commons/commons-compress/1.6/commons-compress-1.6.jar ...
[info] 	[SUCCESSFUL ] org.apache.commons#commons-compress;1.6!commons-compress.jar (1251ms)
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/org/eclipse/jgit/org.eclipse.jgit.archive/3.7.0.201502260915-r/org.eclipse.jgit.archive-3.7.0.201502260915-r.jar ...
[info] 	[SUCCESSFUL ] org.eclipse.jgit#org.eclipse.jgit.archive;3.7.0.201502260915-r!org.eclipse.jgit.archive.jar (660ms)
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/org/eclipse/jgit/org.eclipse.jgit/3.7.0.201502260915-r/org.eclipse.jgit-3.7.0.201502260915-r.jar ...
[info] 	[SUCCESSFUL ] org.eclipse.jgit#org.eclipse.jgit;3.7.0.201502260915-r!org.eclipse.jgit.jar (11511ms)
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/org/eclipse/jgit/org.eclipse.jgit.ui/3.7.0.201502260915-r/org.eclipse.jgit.ui-3.7.0.201502260915-r.jar ...
[info] 	[SUCCESSFUL ] org.eclipse.jgit#org.eclipse.jgit.ui;3.7.0.201502260915-r!org.eclipse.jgit.ui.jar (647ms)
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/org/tukaani/xz/1.4/xz-1.4.jar ...
[info] 	[SUCCESSFUL ] org.tukaani#xz;1.4!xz.jar (1077ms)
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/org/osgi/org.osgi.core/4.3.1/org.osgi.core-4.3.1.jar ...
[info] 	[SUCCESSFUL ] org.osgi#org.osgi.core;4.3.1!org.osgi.core.jar (1438ms)
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/com/googlecode/javaewah/JavaEWAH/0.7.9/JavaEWAH-0.7.9.jar ...
[info] 	[SUCCESSFUL ] com.googlecode.javaewah#JavaEWAH;0.7.9!JavaEWAH.jar(bundle) (933ms)
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/org/apache/httpcomponents/httpclient/4.1.3/httpclient-4.1.3.jar ...
[info] 	[SUCCESSFUL ] org.apache.httpcomponents#httpclient;4.1.3!httpclient.jar (1858ms)
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/org/apache/httpcomponents/httpcore/4.1.4/httpcore-4.1.4.jar ...
[info] 	[SUCCESSFUL ] org.apache.httpcomponents#httpcore;4.1.4!httpcore.jar (1661ms)
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar ...
[info] 	[SUCCESSFUL ] commons-logging#commons-logging;1.1.1!commons-logging.jar (956ms)
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/commons-codec/commons-codec/1.4/commons-codec-1.4.jar ...
[info] 	[SUCCESSFUL ] commons-codec#commons-codec;1.4!commons-codec.jar (769ms)
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/org/codehaus/plexus/plexus-container-default/1.0-alpha-9-stable-1/plexus-container-default-1.0-alpha-9-stable-1.jar ...
[info] 	[SUCCESSFUL ] org.codehaus.plexus#plexus-container-default;1.0-alpha-9-stable-1!plexus-container-default.jar (2315ms)
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/org/codehaus/plexus/plexus-utils/3.0.18/plexus-utils-3.0.18.jar ...
[info] 	[SUCCESSFUL ] org.codehaus.plexus#plexus-utils;3.0.18!plexus-utils.jar (2259ms)
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/org/codehaus/plexus/plexus-io/2.2/plexus-io-2.2.jar ...
[info] 	[SUCCESSFUL ] org.codehaus.plexus#plexus-io;2.2!plexus-io.jar (1426ms)
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/ch/qos/logback/logback-core/1.1.7/logback-core-1.1.7.jar ...
[info] 	[SUCCESSFUL ] ch.qos.logback#logback-core;1.1.7!logback-core.jar (3638ms)
[info] downloading http://maven.aliyun.com/nexus/content/groups/public/org/slf4j/slf4j-api/1.7.20/slf4j-api-1.7.20.jar ...
[info] 	[SUCCESSFUL ] org.slf4j#slf4j-api;1.7.20!slf4j-api.jar (1770ms)

Minimum Scala build. 

name [My Something Project]: hello

Template applied in ./hello

第六坑:国内仓库包不全

虽然把仓库配置改为了使用国内的,但是有很多包还是会去

https://repo1.maven.org/

下载。

第七坑:遇到再来更


相关阅读:

《Scala入坑笔记》一、Scala简介

目录
相关文章
|
5月前
|
Scala
【收藏】Scala常用方法(笔记)
【收藏】Scala常用方法(笔记)
35 0
|
Java 编译器 Scala
Mac VSCode 搭建 Scala 环境跑通 hello world
Mac VSCode 搭建 Scala 环境跑通 hello world
Mac VSCode 搭建 Scala 环境跑通 hello world
|
分布式计算 Scala Spark
Scala写Spark笔记
Scala写Spark笔记
85 0
|
分布式计算 大数据 Scala
|
Scala
疑似bug_中文代码示例之Programming in Scala笔记第九十章
对Programming in Scala书本中的九十章示例代码进行命名中文化, 发现一个问题. Translate identifiers in sample programs to Chinese, and found an issue.
766 0
|
Scala
中文代码示例之Programming in Scala笔记第七八章
对Programming in Scala书本中的七八章示例代码进行命名中文化. Translate identifiers in sample programs to Chinese.
763 0
|
缓存 Scala
中文代码示例之Programming in Scala笔记第四五六章
对Programming in Scala书本中的四五六章示例代码进行命名中文化. Translate identifiers in sample programs to Chinese.
610 0
|
Java Scala API
Scala Symbol笔记
Symbol This class provides a simple way to get unique objects for equal strings. Since symbols are interned, they can be compared using reference equality. symbols可以作为一种快速比较字符串的方式,如果字符串的值相同,则返回的symbol变量具有相同的引用地址。
1214 0