4

我是 Scala 的新手,我发现Scala IDE在我的机器上对于搜索代码库和编辑代码等基本操作非常慢。我习惯了 Visual Studio Code,很高兴找到这个金属扩展

我能够“导入构建”并解决问题,例如在我的项目中提高 scala 版本,但我不确定如何重现此步骤以设置运行配置并在 Scala IDE 中实际启动我们的应用程序。

在此处输入图像描述 在此处输入图像描述

我们有一个父文件夹,其中包含一堆项目和一个“consoleapp”项目,这是我们应用程序的主要入口点 - 它导入所有其他项目的逻辑/路由。

|____parent
| |____consoleapp
| |____project1
| |____project2 

我尝试sbt runsbt runMain consoleapp从 consoleapp 文件夹和父文件夹中,但它们没有工作。

我不确定我们设置中的哪些其他信息是相关的 - 很高兴根据需要提供更多信息。

更新以在下面添加更多详细信息:

控制台应用程序/build.sbt

name := "consoleapp"

version := "1.0"

scalaVersion := "2.12.10"

packMain := Map("consoleapp" -> "consoleapp")

libraryDependencies ++=  Seq (...)

我运行的命令的输出 -sbt runsbt runMain

从 ~/scala/parent 运行

> sbt run                                                                                                                                                                 masterstate [0a8dab85] modified
[info] Loading settings for project global-plugins from metals.sbt,build.sbt ...
[info] Loading global plugins from /Users/pradhyo/.sbt/1.0/plugins
[info] Loading project definition from /Users/pradhyo/scala/parent/project
[info] Loading settings for project consoleapp from build.sbt ...
... 
Loading settings for all other projects in parent folder
...
[info] Loading settings for project parent from build.sbt ...
[info] Resolving key references (22435 settings) ...
[info] Set current project to parent (in build file:/Users/pradhyo/scala/parent/)
[error] java.lang.RuntimeException: No main class detected.
[error]     at scala.sys.package$.error(package.scala:30)
[error] stack trace is suppressed; run last Compile / bgRun for the full output
[error] (Compile / bgRun) No main class detected.
[error] Total time: 1 s, completed 18-Dec-2019 1:41:25 PM

从 ~/scala/parent 运行

> sbt "runMain consoleapp.consoleapp"                                                                                                                                     masterstate [0a8dab85] modified
[info] Loading settings for project global-plugins from metals.sbt,build.sbt ...
[info] Loading global plugins from /Users/pradhyo/.sbt/1.0/plugins
[info] Loading project definition from /Users/pradhyo/scala/parent/project
[info] Loading settings for project consoleapp from build.sbt ...
... 
Loading settings for all other projects in parent folder
...
[info] Loading settings for project parent from build.sbt ...
[info] Resolving key references (22435 settings) ...
[info] Set current project to parent (in build file:/Users/pradhyo/scala/parent/)
[info] running consoleapp.consoleapp 
[error] (run-main-0) java.lang.ClassNotFoundException: consoleapp.consoleapp
[error] java.lang.ClassNotFoundException: consoleapp.consoleapp
[error]     at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
[error] stack trace is suppressed; run last Compile / bgRunMain for the full output
[error] Nonzero exit code: 1
[error] (Compile / runMain) Nonzero exit code: 1
[error] Total time: 0 s, completed 18-Dec-2019 1:46:21 PM

从 ~/scala/parent/consoleapp 运行

> sbt run                                                                                                                                                                 masterstate [0a8dab85] modified
[info] Loading settings for project global-plugins from metals.sbt,build.sbt ...
[info] Loading global plugins from /Users/pradhyo/.sbt/1.0/plugins
[info] Loading project definition from /Users/pradhyo/scala/parent/consoleapp/project
[info] Loading settings for project consoleapp from build.sbt ...
[info] Set current project to consoleapp (in build file:/Users/pradhyo/scala/parent/consoleapp/)
[error] java.lang.RuntimeException: No main class detected.
[error]     at scala.sys.package$.error(package.scala:30)
[error] stack trace is suppressed; run last Compile / bgRun for the full output
[error] (Compile / bgRun) No main class detected.
[error] Total time: 0 s, completed 18-Dec-2019 1:49:26 PM

从 ~/scala/parent/consoleapp 运行

> sbt "runMain consoleapp"                                                                                                                                                masterstate [0a8dab85] modified
[info] Loading settings for project global-plugins from metals.sbt,build.sbt ...
[info] Loading global plugins from /Users/pradhyo/.sbt/1.0/plugins
[info] Loading project definition from /Users/pradhyo/scala/parent/consoleapp/project
[info] Loading settings for project consoleapp from build.sbt ...
[info] Set current project to consoleapp (in build file:/Users/pradhyo/scala/parent/consoleapp/)
[info] running consoleapp 
[error] (run-main-0) java.lang.ClassNotFoundException: consoleapp
[error] java.lang.ClassNotFoundException: consoleapp
[error]     at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
[error] stack trace is suppressed; run last Compile / bgRunMain for the full output
[error] Nonzero exit code: 1
[error] (Compile / runMain) Nonzero exit code: 1
[error] Total time: 1 s, completed 18-Dec-2019 1:50:06 PM
4

2 回答 2

3

按照Scala Metals VSCode 自述文件中的说明进行操作后,对问题中的 Eclipse 屏幕截图使用与此类似的启动配置。

.vscode/launch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "scala",
            "name": "Debug consoleapp",
            "request": "launch",
            "mainClass": "consoleapp",
            "buildTarget": "consoleapp",
            "args": [],
            "jvmOptions": ["-J-Dconfig.file=/path/to/config/file"]
        }
    ]
}

我无法正确传递pureconfig的配置文件。这是正确行的 Github 问题。jvmOptions

于 2020-05-19T13:31:39.843 回答
0

Metals 支持这些 Scala 版本 2.13.0、2.13.1、2.12.8、2.12.9、2.12.10、2.12.7 和 2.11.12

这是我从他们的文档(doc)中注意到的。所以它可以指出我在评论中提到的你和我的问题。

scalaVersion := "2.12.3"的不在此处列出。

于 2019-12-20T08:29:40.747 回答