scala shell 使用第三方jar包
所属分类 scala
浏览量 741
scala shell 交互模式 REPL read–eval–print loop
默认只加载 scala 和 java标准库
build.sbt 增加依赖
// scalaVersion := "2.13.8"
libraryDependencies += "com.alibaba" % "fastjson" % "1.2.62"
sbt console 进入REPL模式
sbt console
[info] Updated file /Users/dugang/dugang/my/hellocode/demo/scala/sbt-scala-shell/project/build.properties: set sbt.version to 1.6.1
[info] welcome to sbt 1.6.1 (Oracle Corporation Java 1.8.0_321)
[info] loading global plugins from /Users/dugang/.sbt/1.0/plugins
[info] loading project definition from /Users/dugang/dugang/my/hellocode/demo/scala/sbt-scala-shell/project
[info] loading settings for project sbt-scala-shell from build.sbt ...
[info] set current project to sbt-scala-shell (in build file:/Users/dugang/dugang/my/hellocode/demo/scala/sbt-scala-shell/)
[info] Starting scala interpreter...
Welcome to Scala 2.12.15 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_321).
Type in expressions for evaluation. Or try :help.
生成 project 和 target 目录
import com.alibaba.fastjson.JSON
import java.util.ArrayList
val list = new java.util.ArrayList[Int]()
list.add(1)
list.add(2)
JSON.toJSONString(list, true)
JSON.toJSONString(list,false)
项目根目录增加
JavaHello.java
ScalaHello.java
public class JavaHello {
public static void main(String[] args) throws Exception {
System.out.println("hello java");
}
}
object ScalaHello {
def main(args: Array[String]): Unit = {
println("hello scala");
}
}
运行sbt console 进入交互模式
[info] compiling 1 Scala source and 1 Java source to /Users/dugang/dugang/my/hellocode/demo/scala/sbt-scala-shell/target/scala-2.12/classes ...
[info] Starting scala interpreter...
target/scala-2.12/classes
编译生成的class文件
JavaHello.class
ScalaHello$.class
ScalaHello.class
scala> JavaHello.main(null)
hello java
scala> ScalaHello.main(null)
hello scala
https://gitee.com/dyyx/hellocode/tree/master/demo/scala/sbt-scala-shell
上一篇
下一篇
scala try future 例子
scala Play框架 依赖注入 guice 使用说明
sbt自定义任务
sbt hello 例子
gradle入门
分布式任务调度框架Temporal介绍