如何从 Scala 内部获取 Scala 版本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6121403/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I get the Scala version from within Scala itself?
提问by mlvljr
This is not about command-line compiler options. How do I programmatically obtain the Scala version inside code?
这与命令行编译器选项无关。如何以编程方式获取代码中的 Scala 版本?
Alternatively, where does the Eclipse Scala plugin v2 store the path to scalac?
或者,Eclipse Scala 插件 v2 在哪里存储路径scalac?
回答by Paul Butcher
This will work without access to scala-compiler.jar:
这将在没有访问权限的情况下工作scala-compiler.jar:
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26).
Type in expressions to have them evaluated.
Type :help for more information.
scala> util.Properties.versionString
res0: java.lang.String = version 2.9.1.final
回答by Naga Vijayapuram
There are three ways to get the Scala version -
可以通过三种方式获取 Scala 版本 -
scala> util.Properties.versionNumberString
res103: String = 2.11.4
scala> util.Properties.versionString
res104: String = version 2.11.4
scala> util.Properties.versionMsg
res105: String = Scala library version 2.11.4 -- Copyright 2002-2013, LAMP/EPFL
回答by HairyFotr
You can get the Scala version like this:
您可以像这样获得 Scala 版本:
scala> scala.tools.nsc.Properties.versionString
res7: java.lang.String = version 2.9.0.final
I don't know the specifics of the plugin, though.
不过,我不知道插件的具体细节。
回答by Chinya
We can also get installed Scala version
我们还可以安装 Scala 版本
- Open command prompt
- type Scala
- You will get following output:
- 打开命令提示符
- 类型 Scala
- 您将获得以下输出:
Welcome to Scala version 2.10.3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_6 0). Type in expressions to have them evaluated. Type :help for more information.
欢迎使用 Scala 版本 2.10.3(Java HotSpot(TM) 64 位服务器 VM,Java 1.8.0_6 0)。输入表达式以对它们进行评估。输入 :help 以获取更多信息。

