gpt4 book ai didi

scala - 如何在 sbt 下使用 Quasar 和 Scala?

转载 作者:行者123 更新时间:2023-12-04 12:20:52 25 4
gpt4 key购买 nike

我想用 Quasar在我的 SBT 项目中。自 Scala is not yet supported剩下的唯一可行的选择是让 SBT 编译一些使用 Quasar 的 Java 类。

我试过放

javaOptions += "-javaagent:PATH_TO_JAR/quasar-core-0.5.0.jar"


fork := true

正如我读到的那样使用例如JRebel 必须将这两个语句都插入到 build.sbt 中

但它似乎也不起作用,因为使用 Quasarish 类( QuasarExample )会产生:
[error]    IllegalArgumentException: : Fiber class HelloWorldSpec$$anonfun$1$$anonfun$apply$3$$anon$1 has not been instrumented.  (Fiber.java:151)
[error] co.paralleluniverse.fibers.Fiber.<init>(Fiber.java:151)
[error] co.paralleluniverse.fibers.Fiber.<init>(Fiber.java:171)
[error] co.paralleluniverse.fibers.Fiber.<init>(Fiber.java:448)

一段代码在成功检测后预计会无错误地运行:
new Fiber<Integer>() {
@Override
protected Integer run() throws SuspendExecution, InterruptedException {
return 0;
}
}.start();

另见 this repository首先。

最佳答案

根据@mjaskowski 的评论,Dou you plan to instrument bytecode produced by Scala compiler? , Scala 还不是受支持的语言。

Short answer is: absolutely. Longer answer is, yes, but not very soon. Scala is a very (very, very, very, very) complex language (oh my god, it's so incredibly complex!), and it would take a long time to test Quasar with the many (many-many-many) Scala features. Given the relatively small number of Scala developers, and the heavy integration costs, this may take some time. We do, however support Clojure (much simpler integration), and will soon probably (or maybe we already do) support Kotlin (trivial integration).



继续查看在 sbt 中设置 javaagent 的可能方法。

这是我第一次遇到 Quasar,所以这些步骤非常基本,但它们应该让你有一个良好的开端。

单独在 JVM 中运行 Quasar 的 javaagent

只有使用以下命令才能在没有任何 Scala/sbt jar 的情况下运行 Quasar 的 javaagent。

java -cp /Users/jacek/.ivy2/cache/org.ow2.asm/asm-util/jars/asm-util-5.0.1.jar:/Users/jacek/.ivy2/cache/org.ow2.asm/asm-commons/jars/asm-commons-5.0.1.jar:/Users/jacek/.ivy2/cache/org.ow2.asm/asm/jars/asm-5.0.1.jar -javaagent:/Users/jacek/.ivy2/cache/co.paralleluniverse/quasar-core/jars/quasar-core-0.5.0.jar -help



它似乎不是独立的,需要在 CLASSPATH 上添加额外的 jars。 .

使用 Scala 运行 Quasar 的 javaagent

以下命令使 scala和 Quasar 的 javaagent 很高兴。

scala -debug -usebootcp -toolcp /Users/jacek/.ivy2/cache/org.ow2.asm/asm-tree/jars/asm-tree-5.0.1.jar:/Users/jacek/.ivy2/cache/org.ow2.asm/asm-util/jars/asm-util-5.0.1.jar:/Users/jacek/.ivy2/cache/org.ow2.asm/asm-commons/jars/asm-commons-5.0.1.jar:/Users/jacek/.ivy2/cache/org.ow2.asm/asm/jars/asm-5.0.1.jar:/Users/jacek/.ivy2/cache/org.ow2.asm/asm-analysis/jars/asm-analysis-5.0.1.jar -J-javaagent:/Users/jacek/.ivy2/cache/co.paralleluniverse/quasar-core/jars/quasar-core-0.5.0.jar



使用 sbt 运行 Quasar 的初步尝试

build.sbt中添加Quasar的必要依赖:
val quasarDeps = Seq(
"quasar-core",
"quasar-actors",
"quasar-galaxy"
)

libraryDependencies := quasarDeps.map("co.paralleluniverse" % _ % "0.5.0")

归结为增加 libraryDependencies有必要的 jar 。我选择了所有可用的。

我检查了 Scala console图书馆是可用的。
➜  quasar-sbt  xsbt
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Set current project to quasar-sbt (in build file:/Users/jacek/sandbox/quasar-sbt/)
> console
Welcome to Scala version 2.10.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_60).
Type in expressions to have them evaluated.
Type :help for more information.

scala> import co.paralleluniverse.fibers._
import co.paralleluniverse.fibers._

scala> Fiber.DEFAULT_STACK_SIZE
res0: Int = 32

您还必须添加 java 代理。将以下内容添加到 build.sbt :
// FIXME the path to quasar-core should be simpler
javaOptions in Test += "-javaagent:/Users/jacek/.ivy2/cache/co.paralleluniverse/quasar-core/jars/quasar-core-0.5.0.jar"

fork in Test := true

// only needed for Specs2 so I could test the test setup
libraryDependencies += "org.specs2" %% "specs2" % "2.3.13" % Test

scalacOptions in Test ++= Seq("-Yrangepos")
reload构建变化。
> reload
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Set current project to quasar-sbt (in build file:/Users/jacek/sandbox/quasar-sbt/)

编写一个测试以确保所有设置都正确。我用了 HelloWorldSpec来自 [Specs2][2]有一些变化:
import org.specs2.mutable._

import co.paralleluniverse.fibers._

class HelloWorldSpec extends Specification {

"Quasar" should {
"Fiber.DEFAULT_STACK_SIZE defaults to 32" in {
Fiber.DEFAULT_STACK_SIZE === 32
}
}
}

这不是一个非常广泛的测试,因此请根据您的需要对其进行调整。将文件保存在 src/test/scala 下.

执行 test .
> test
objc[27427]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home/jre/bin/java and /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
[info] HelloWorldSpec
[info]
[info] Quasar should
[info] + Fiber.DEFAULT_STACK_SIZE defaults to 32
[info]
[info] Total for specification HelloWorldSpec
[info] Finished in 40 ms
[info] 1 example, 0 failure, 0 error
[info] Passed: Total 1, Failed 0, Errors 0, Passed 1
[success] Total time: 4 s, completed Jul 13, 2014 2:04:13 PM

有用!

关于scala - 如何在 sbt 下使用 Quasar 和 Scala?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24722233/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com