使用 simple-build-tool (sbt) 和 IntelliJ 调试 Scala 代码

发布于 2024-10-01 12:06:57 字数 283 浏览 8 评论 0原文

使用 IntelliJ 的内置调试器调试 sbt 管理的 Scala 代码的最简单方法是什么? 来自 sbt 的 Google 代码网站的“RunningSbt”文档列出了命令用于运行项目或测试的主类,但似乎没有用于调试的命令。

后续问题:使用 sbt 的 jetty-run 命令时,将 IntelliJ 的调试器附加到 Jetty 的最简单方法是什么?

What's the easiest way to debug Scala code managed by sbt using IntelliJ's built-in debugger? The documentation from "RunningSbt" from sbt's google code site lists commands for running the main class for a project or the tests, but there seem to be no commands for debugging.

Follow-up question: what's the easiest way to attach IntelliJ's debugger to Jetty when using sbt's jetty-run command?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(15

逆蝶 2024-10-08 12:06:57

官方 适用于 Mac、Linux 和 Linux 的 SBT 软件包 Windows。您可以使用该标志来指定调试端口:

sbt -jvm-debug 5005

底层,这将使用典型的详细调试咒语启动 SBT 的 JVM:

-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005

您现在可以正常运行代码,例如使用 sbt run 命令。

配置 IntelliJ 以连接到正在运行的代码...

现在,您可以使用 远程调试配置。请注意,此表单中的上面 3 个字段虽然令人恐惧,但只是供您将文本复制到其中,而不是复制到其中(它们给出了上面指定的详细调试咒语,其中 - jvm-debug 已经为您处理好了) - 您可以更改的唯一配置位于中间的 Settings 部分:

IntelliJ 中的远程调试配置

There's a very convenient -jvm-debug flag in the official SBT packages for Mac, Linux & Windows. You can use the flag to specify the debug port:

sbt -jvm-debug 5005

Under the covers, this starts the JVM for SBT with the typical verbose debugging incantation:

-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005

You now can run your code as normal, for example with the sbt run command.

Configuring IntelliJ to connect to the running code...

Now you connect IntelliJ to your running process using a Remote Debug configuration. Note that the upper 3 fields in this form, while scary, are just for you to copy text out of, rather than into (they're giving the verbose debugging incantation specified above, which -jvm-debug already takes care of for you) - the only configuration you can change is in theSettings section halfway down:

Remote Debug configuration in IntelliJ

别忘他 2024-10-08 12:06:57

对于 IntelliJ 中的普通调试,您可以按照通常的方式使用应用程序运行/调试配置,无论您是否使用 sbt 来编译代码。

要连接到在 Jetty 中运行的应用程序,您需要创建远程调试配置。当您这样做时,IntelliJ 将为您提供一组用于运行远程 JVM 的命令行参数——类似于

-Xdebug -Xrunjdwp:transport=dt_socket,服务器=y,挂起=n,地址=5005

使用这些参数启动 sbt,然后执行 jetty-run。最后,在 IntelliJ 中启动远程调试配置。 此帖子可能有用。

For ordinary debugging in IntelliJ, you can use an Application run/debug configuration in the usual way, regardless of whether you're using sbt to compile your code.

To connect to your application running in Jetty, you'll need to create a Remote debug configuration. When you do so, IntelliJ will give you a set of command line arguments for running the remote JVM -- something like

-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005

Launch sbt with these arguments and then execute jetty-run. Finally, launch your remote debug configuration in IntelliJ. This thread might be useful.

Hello爱情风 2024-10-08 12:06:57

我在这方面也遇到了一些麻烦,因此冒着过于详细的风险,这就是我所做的:

SETUP

  1. 为 sbt jetty-run 创建运行配置

    • 转到“运行”>编辑配置
    • 单击 [+] 图标并选择 Scala 编译服务器
    • 输入您想要的任何名称,然后单击“运行 SBT 操作”复选框并从 [...] 中选择 SBT 操作 jetty-run
  2. 创建调试配置用于远程调试

    • 转到“运行”>编辑配置
    • 点击 [+] 图标并选择远程
    • 输入您想要的任何名称并复制行 -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 (确保单击“确定”以实际创建配置)
  3. 设置 sbt 插件以运行上面的虚拟机选项

    • 转到文件>设置> SBT
    • 将行 -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 粘贴到虚拟机参数框中已有的参数后面

DEBUGGING

  1. 后面根据需要设置断点
  2. 来启动 jetty Web 服务器。运行或单击绿色箭头
  3. 通过选择上面创建的远程调试配置并选择“运行”>“启动远程调试器”。调试或单击错误图标

I had some trouble with this too, so at the risk of being overly detailed, here's what I did:

SETUP

  1. Create a run configuration for sbt jetty-run

    • Go to Run > Edit Configurations
    • Click the [+] icon and choose Scala Compilation Server
    • Enter whatever name you want, and click the "Run SBT Action" checkbox and select the SBT Action jetty-run from the [...]
  2. Create a debug configuration for remote debugging

    • Go to Run > Edit Configurations
    • Click the [+] icon and choose Remote
    • Enter whatever name you want and copy the line -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 (make sure to click OK to actually create the configuration)
  3. Set up sbt plugin to run the vm options above

    • Go to File > Settings > SBT
    • Paste the line -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 in the VM parameters box, after the ones that are already there

DEBUGGING

  1. Set breakpoints as desired
  2. Start the jetty web server by choosing the sbt jetty-run configuration you created above and choosing Run > Run or by clicking the green arrow
  3. Start the remote debugger by choosing the remote debugging configuration you created above and choosing Run > Debug or by clicking the bug icon
您的好友蓝忘机已上羡 2024-10-08 12:06:57

这对我来说每次都有效,唯一需要设置的是 IntelliJ 中的远程调试;我从 IntelliJ 的终端使用 JVM 参数启动 SBT:

sbt -J-Xdebug -J-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005

之后我可以在 localhost:5005 上启动远程调试

This one works for me every time, and the only thing you need to set up is remote debugging in IntelliJ; I start up SBT with JVM parameters from the terminal in IntelliJ:

sbt -J-Xdebug -J-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005

After that I can start remote debugging on localhost:5005

西瓜 2024-10-08 12:06:57

这些答案或提供的链接都不适合我,所以一旦我弄清楚了这一点,我想我会分享...

包括我开始时没有的背景理解...

这主要基于说明< a href="https://web.archive.org/web/20141228045746/http://exit4b.com:80/blog/2013/10/01/debugging-scala-sbt-intellij" rel="nofollow noreferrer" >这里只是有额外的解释帮助我完成它。感谢@AndrewBucknell 在该链接断开后恢复了这篇文章(下面的评论)。 原始死链接在这里

我的环境:
Scala 2.10.2、SBT 0.13 和 IntelliJ 13.1

背景:

  • 无论出于何种原因,在 IntelliJ 中使用 SBT 编译 Scala 并没有像 Maven 项目那样集成(这样可以非常轻松地进行调试)。
  • 据我了解,使用 SBT 编译时,您是在单独的进程中进行编译,因此,您需要进行远程调试。

什么是调试?

  • 调试是一种运行 JVM 或应用的模式,可让您控制代码执行流程。
  • 然后,您使用的调试工具可以向调试引擎发出命令,告诉它“执行下一行代码,然后再次暂停”或“继续执行”或“获取内存中存储的变量的值”。< /里>

什么是远程调试?

  • 远程调试是通过网络连接(套接字)进行调试。
  • 此网络连接允许您从远程计算机向调试引擎发出命令。
  • 当您想要调试远程服务器上运行的代码时,这很有用,但是
  • 对于 Scala 代码在 SBT 下运行并通过独立于 IntelliJ 环境的 Web 服务器(例如 Jetty 或 Tomcat)启动等情况也很有用。

参考上面的链接,以下解释/修改很有用:

  1. 设置 IntelliJ 以使用“启用调试”JVM 设置启动 SBT,包括设置网络套接字时要使用的端口。 (不变)将指定的 VM 参数添加到您的 IntelliJ 设置中。
  2. 确保此处的端口号与第 1 步中的 JVM 设置相符。
  3. 启动 SBT 时,您需要通过 SBT 控制台插件(即您在步骤 1 中配置的内容)执行此操作。如果您在 IntelliJ 之外(在命令行)运行 SBT,则需要使用步骤 1 中的相同虚拟机参数启动 SBT(我没有这样做;所以没有说明)。在此步骤之后,SBT 现在正在运行(但您的代码尚未运行),并且 JVM 已设置为远程调试。
  4. 这将启动 IntelliJ 调试工具,该工具会连接到您在第 3 步中启动的 JVM。
  5. 最后,您在 SBT 控制台中开始编译。您可以使用任何编译命令(包括连续编译命令)来执行此操作。如果连续重新编译,重新编译将会发生,但不会在调试器暂停代码执行时发生。

None of these answers or provided links worked for me, so once I figured this out, I figured I'd share...

including the background understanding I didn't have when I started...

This is based mostly on the instructions here just with additional explanation that carried me through it. Thanks to @AndrewBucknell for recovering the article after this link broke (comment below). original dead link here

My Environment:
Scala 2.10.2, SBT 0.13, and IntelliJ 13.1

Background:

  • For whatever reason, using SBT to compile Scala in IntelliJ isn't integrated the way Maven projects are (which allow debugging really easily).
  • It appears from my understanding that when compiling with SBT, you're compiling in a separate process, therefore, you need to be remotely debugging.

What is Debugging?

  • Debugging is a mode you can run your JVM or app in that allows you to control the flow of code execution.
  • The Debugging Tool you use can then issue commands to the Debugging Engine that tells it "execute the next line of code then pause again" or "continue executing" or "get the value of the variable stored here in memory".

What is Remote Debugging?

  • Remote Debugging is debugging over a network connection (socket).
  • This network connection allows you to issue the commands to the Debug Engine from a remote machine.
  • This is useful for when you want to debug code that's running on a remote server, BUT
  • It's also useful for situations like Scala code running under SBT and launching via a web server, such as Jetty or Tomcat, separate from your IntelliJ environment.

Referencing the link above, the following explanations/modifications are useful:

  1. Setup IntelliJ to launch SBT with the "enable debugging" JVM settings, including the port to use when setting up the network socket. (unchanged) add the named VM parameters to your IntelliJ settings.
  2. Ensure your port number here matches your JVM settings from Step 1.
  3. When you launch SBT, you need to do it from the SBT Console plugin (which is what you configured in Step 1). If you're running SBT outside of IntelliJ (at the commandline), you'll need to launch SBT with the same VM parameters from Step 1 (I didn't do this; so no instructions). After this step, SBT is now running (but your code is not yet) and the JVM is setup for Remote Debugging.
  4. This starts the IntelliJ Debugging Tool, which connects to the JVM you started in Step 3.
  5. Finally, you start the compilation in the SBT Console. You can do this with any compilation command, including a continuous compilation command. If continuous re-compile, the recompile will happen, but not while code execution is paused by the debugger.
给妤﹃绝世温柔 2024-10-08 12:06:57

我在这里添加另一个答案,因为我在查找相关问题时发现了这个问题:使用断点调试测试类。

我正在使用 ScalaTest,并且通常使用 sbt 的“仅测试”命令运行套件。现在,当我想使用交互式调试器时,我可以执行以下操作:

创建一个类型为“ScalaTest”的新运行/调试配置,输入主“测试类:”名称,然后选择“启动前:运行 SBT 操作'测试” -编译'”。就是这样,您现在可以在测试源中放置断点,并运行此配置。

I am adding another answer here, because I found this question when looking up a related problem: Debugging test classes using breakpoints.

I am using ScalaTest, and I typically run a suite using sbt's 'test-only' command. Now when I want to use the interactive debugger, I can do the following:

Create a new Run/Debug Configuration of type 'ScalaTest', put the main "Test Class:" name, and choose "Before launch: Run SBT Action 'test-compile'". That's it, you can place breakpoints now in the test sources, and run this configuration.

赤濁 2024-10-08 12:06:57

我也一直在努力在 Windows 上使用 Intellij 通过 SBT 构建的 Spray-can / Akka / Scala 应用程序进行调试。将各种建议拼凑在一起,对我来说最简单的方法是:

  1. 确保您的项目/plugsin.sbt 文件中有 sbt.Revolver,例如

    addSbtPlugin("io.spray" % "sbt-revolver" % "0.7.1")

  2. 在 build.sbt 文件中设置 javaoptions:

    javaOptions := Seq("-Xdebug", "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005")

特别要使用 suspend=y 选项。这将保留该应用程序,直到您从 Intellij 连接远程调试器

  1. 通过“运行/编辑配置”菜单在 Intellij 中设置调试器配置。按+按钮,选择“远程”选项。确保条目与上面的 javaoptions 匹配,特别是端口地址 5005。为配置指定一个名称,例如“Spray”。

  2. 从 SBT 控制台使用重新启动命令。您应该在反馈输出中看到 5005 端口地址。

  3. 在 Intellij 中设置断点。

  4. 从 Intellij 中,选择“运行\调试‘Spray’”。这应该连接到喷雾罐网络服务器。您应该能够在调试窗口中看到很多线程。

  5. 请注意,Spray 中的某些 Get 指令似乎在启动时执行,但在调用网站时不会重复执行。

I've been struggling with debugging too on Windows with a Spray-can / Akka / Scala app built via SBT, using Intellij. Piecing together various suggestions, the simplest approach for me was:

  1. Make sure you have sbt.Revolver in your project/plugsin.sbt file e.g.

    addSbtPlugin("io.spray" % "sbt-revolver" % "0.7.1")

  2. Set javaoptions in you build.sbt file:

    javaOptions := Seq("-Xdebug", "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005")

In particular use the suspend=y option. This will hold the app until you connect a remote debugger from Intellij

  1. Set up a debugger configuration in Intellij via Run / Edit Configurations menu. Press the + button, select the "Remote" option. Make sure the entries match the javaoptions above, in particular the port address of 5005. Give the config a name like 'Spray'.

  2. From your SBT console use the re-start command. You should see the 5005 port address in the feedback output.

  3. In Intellij set your breakpoints.

  4. From Intellij, select the Run \ Debug 'Spray'. This should connect to the spray-can web server. You should be able to see a lot of threads in the debug window.

  5. Beware that some of the Get directives in Spray seem to get executed on start up but not repeatedly on calling the website.

天邊彩虹 2024-10-08 12:06:57

文件->设置->其他设置->SBT
虚拟机参数
-Xmx512M -XX:MaxPermSize=256M -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005

运行->编辑配置
按+,然后选择远程
按“立即应用”

当您执行命令“run”时,在 SBT 控制台(由 intelliJ 内部启动)中

,您将看到“在地址:5005 监听传输 dt_socket” ,现在按“运行”->“调试”。您将看到下面的调试菜单已激活。它有两个选项卡“调试器”和“控制台”。

使用F7从下一行到下一行

我选择暂停为n。当我运行 run 命令时它被卡住了

File->Settings->Other Settings->SBT
VM parameters
-Xmx512M -XX:MaxPermSize=256M -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005

Run->Edit Configurations
Press + and then select remote
Press Apply

Now in the SBT console (Started inside by intelliJ) when you execute the command 'run' You will see "Listening for transport dt_socket at address: 5005"

Now press Run->Debug. You will see the debug menus below activated. It has two tabs Debugger and Console.

Use F7 to from next line to next

I chose suspend to be n. With it being y when I ran the run command it was stuck

伏妖词 2024-10-08 12:06:57
export SBT_OPTS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5009

试试这个

export SBT_OPTS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5009

try this

挽你眉间 2024-10-08 12:06:57

对于 Windows 人员来说,编辑 %SBT_HOME%\bin\sbt.bat 并找到以下代码行:

:run

"%_JAVACMD%" %_JAVA_OPTS% %SBT_OPTS% -cp "%SBT_HOME%sbt-launch.jar" xsbt.boot.Boot %*
if ERRORLEVEL 1 goto error
goto end

然后将其替换为以下代码:

FOR %%a IN (%*) DO (
  if "%%a" == "-jvm-debug" (
    set JVM_DEBUG=true
    set /a JVM_DEBUG_PORT=5005 2>nul >nul
  ) else if "!JVM_DEBUG!" == "true" (
    set /a JVM_DEBUG_PORT=%%a 2>nul >nul
    if not "%%a" == "!JVM_DEBUG_PORT!" (
      set SBT_ARGS=!SBT_ARGS! %%a
    )
  ) else (
    set SBT_ARGS=!SBT_ARGS! %%a
  )
)

if defined JVM_DEBUG_PORT (
  set _JAVA_OPTS=!_JAVA_OPTS! -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=!JVM_DEBUG_PORT!
)

call :run %SBT_ARGS%

if ERRORLEVEL 1 goto error
goto end

:run
"%_JAVACMD%" %_JAVA_OPTS% %SBT_OPTS% -cp "%SBT_HOME%sbt-launch.jar" xsbt.boot.Boot %*
goto :eof

我可以做的最好的事情是为 -jvm-debug 在 Bash 脚本启动器中看到时

注意。我不认为 %SBT_HOME% 实际上存在于这个脚本之外,除非你在你的环境中明确创建,但无论如何你明白了:D

For what it's worth Windows folk, edit %SBT_HOME%\bin\sbt.bat and locate the following lines of code:

:run

"%_JAVACMD%" %_JAVA_OPTS% %SBT_OPTS% -cp "%SBT_HOME%sbt-launch.jar" xsbt.boot.Boot %*
if ERRORLEVEL 1 goto error
goto end

then replace them with this code:

FOR %%a IN (%*) DO (
  if "%%a" == "-jvm-debug" (
    set JVM_DEBUG=true
    set /a JVM_DEBUG_PORT=5005 2>nul >nul
  ) else if "!JVM_DEBUG!" == "true" (
    set /a JVM_DEBUG_PORT=%%a 2>nul >nul
    if not "%%a" == "!JVM_DEBUG_PORT!" (
      set SBT_ARGS=!SBT_ARGS! %%a
    )
  ) else (
    set SBT_ARGS=!SBT_ARGS! %%a
  )
)

if defined JVM_DEBUG_PORT (
  set _JAVA_OPTS=!_JAVA_OPTS! -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=!JVM_DEBUG_PORT!
)

call :run %SBT_ARGS%

if ERRORLEVEL 1 goto error
goto end

:run
"%_JAVACMD%" %_JAVA_OPTS% %SBT_OPTS% -cp "%SBT_HOME%sbt-launch.jar" xsbt.boot.Boot %*
goto :eof

Best I can do to get same behaviour for -jvm-debug when seen in the Bash script launcher

NB. I don't think %SBT_HOME% actually exists outside this script, unless you created explicitly in you environment, but anyway you get the point :D

段念尘 2024-10-08 12:06:57

AttachMe IntelliJ 插件可能是附加调试器的更快方式,而无需摆弄端口号:

AttachMe 会自动附加 IntelliJ 调试器,即使您
从终端(或任何其他方式)启动您的应用程序。你不需要
手动触发附加到进程操作。

博客文章自述文件有设置说明,但是我必须对它们进行一些更改才能使其在我的计算机上运行

  1. 下载 来自官方仓库的 installer.sh 脚本

    curl -o installer.shhttps://raw.githubusercontent.com/JetBrains/attachme/master/installer.sh
    
  2. 赋予其可执行权限 chmod u+x installer.sh
  3. 使用 ./installer.sh 运行它
  4. 这应该在 /.config/attachme/agent.jar 并创建 ~/.attachme 文件
  5. 修改 ~/.attachme 以包含

    AM_JDWP_ARGS="transport=dt_socket,服务器=y,挂起=y,地址=127.0.0.1:0"
    echo 使用 JDWP 参数 ${AM_JDWP_ARGS}
    导出 JAVA_TOOL_OPTIONS="- javaagent:/Users/mario_galic/.config/attachme/agent.jar -agentlib:jdwp=${AM_JDWP_ARGS}"
    echo "AttachMe配置成功"
    
  6. 安装相应的Attachme插件并重启:IntelliJ |偏好 |插件

  7. 创建Attachme 运行配置:Run |编辑配置... |添加新配置 |附上调试器注册表| OK

在这些一次性的恶作剧之后,我们可以通过

  1. Start Attachme run configuration
  2. source ~/.attachme
  3. 从终端启动应用程序来自动附加调试器,也许, < code>sbt "runMain example.Hello"
  4. 调试器应自动附加并在任何断点处停止

AttachMe IntelliJ plugin is potentially faster way off attaching the debugger without having to fiddle with port numbers:

AttachMe will attach the IntelliJ debugger automatically even if you
start your app from terminal (or any other way). You don't need to
trigger Attach to process action manually.

Blog post and readme have setup instructions, however I had to alter them a bit to get it working on my machine

  1. Download installer.sh script from official repo

    curl -o installer.shhttps://raw.githubusercontent.com/JetBrains/attachme/master/installer.sh
    
  2. Give it executable permissions chmod u+x installer.sh
  3. Run it with ./installer.sh
  4. This should install the agent under /.config/attachme/agent.jar and create ~/.attachme file
  5. Modify ~/.attachme to contain

    AM_JDWP_ARGS="transport=dt_socket,server=y,suspend=y,address=127.0.0.1:0"
    echo Using JDWP arguments ${AM_JDWP_ARGS}
    export JAVA_TOOL_OPTIONS="- javaagent:/Users/mario_galic/.config/attachme/agent.jar -agentlib:jdwp=${AM_JDWP_ARGS}"
    echo "AttachMe configured successfully"
    
  6. Install corresponding Attachme plugin and restart: IntelliJ | Preferences | Plugins

  7. Create Attachme run configuration: Run | Edit configurations... | Add new configuration | Attachme debugger registry | OK

After these one-off shenanigans, we can attach a debugger automatically by

  1. Start Attachme run configuration
  2. source ~/.attachme
  3. Start application from terminal, perhaps, sbt "runMain example.Hello"
  4. The debugger should automatically attach and stop at any breakpoint
分分钟 2024-10-08 12:06:57

关于相对较新版本的Intellij(2020.1.4),一步一步给分:

  • 配置Intellij

    • “编辑配置”
      输入图片此处描述
    • 添加“远程”
      这个新版本的Intellij不允许你编辑“命令行参数”中的字符串,你只能编辑上面的“主机”和“端口”,我保留默认值;我只是将下面的“模块路径”更改为“root”(不确定是否有必要)
      输入图片此处描述
  • 远程调试

    • 设置断点
    • 命令行中执行sbt命令,例如sbt -jvm-debug 5005 test
    • 立即返回 Intellij 并单击“调试”,它应该显示类似“已连接到 xxx”的内容,然后等待它在断点处挂起
      输入图片此处描述

Give a cent step by step regarding a relatively new version of Intellij (2020.1.4):

  • Configure Intellij

    • "Edit Configurations"
      enter image description here
    • Add "Remote"
      This new version of Intellij does not allow you to edit the string in the "Command line arguements", you can only edit the "Host" and "Port" above, which I leave it default; I only change the "module path" below to "root" (not sure if it's necessary)
      enter image description here
  • Remote debug

    • Set your break point
    • Execute sbt command in command line, e.g. sbt -jvm-debug 5005 test
    • Immediately go back to Intellij and click on "Debug", it should show something like "Connected to xxx", then wait till it suspends at your break point
      enter image description here
一身骄傲 2024-10-08 12:06:57

我也遇到了同样的问题,我想分享一下我是如何解决的。顺便说一下,我使用的是 Ubuntu 14.04 和 IntelliJ 15。

  1. 在设置 -> SBT->
    将以下行粘贴到 VM 参数文本框中:

    -XX:MaxPermSize=384M -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005

  2. 在 IntelliJ 中打开 Termilal 并运行:

    sbt -jvm-调试 5005

    注意:您应该在终端中看到这一行:“在地址:5005 监听传输 dt_socket”

  3. 编辑配置 ->点击+->选择“远程”

    <前><代码>我。给出一些名称示例:DebugMyModule

    二.所有需要的配置都会自动设置,但您只需验证即可。在命令行参数中,应类似于“-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005”。

    三.在“在模块的类路径中搜索源”文本框中指定您的模块,您的测试用例位于哪个模块中。

    四.将 127.0.0.1 主机代替“localhost”。 “本地主机”不适合我。

  4. 编辑配置列表框中选择DebugMyModule,然后单击调试

    注意:您应该看到调试视图已打开,并且在调试控制台中您应该能够看到“已连接到目标虚拟机,地址:'127.0.0.1:5005' , Transport: 'socket'"

  5. 在您的测试类中的几个测试用例中放置断点。

  6. 进入运行“sbt -jvm-debug 5005”的终端并按如下方式运行

    项目 <您的模块名称>
    it:testOnly 包.TestSpec
    

    例如: com.myproject.module.AddServiceTest[Spec]

  7. 您可以看到调试在测试用例断点中启动。

I also got the same problem, I like to share how I resolved. By the way I am using Ubuntu 14.04 and IntelliJ 15.

  1. In Setting -> SBT ->
    Pasted below line in VM Parameters text box:

    -XX:MaxPermSize=384M -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005

  2. Opened Termilal in IntelliJ and run:

    sbt -jvm-debug 5005

    Note: you should see this line in terminal: "Listening for transport dt_socket at address: 5005"

  3. Edit Configurations -> Click + -> Select 'Remote'

    I. Give some name example: DebugMyModule
    
    II. All needed configurations will be set automatically, But you just verify. In Command line arguments should look like this "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005".
    
    III. In 'Search Sources in Module's Classpath' text box specify your module in which module your test cases are there.
    
    IV. put 127.0.0.1 host instead of 'localhost'. 'localhost' not working for me.
    
  4. Select DebugMyModule in Edit Configurations list box and click Debug.

    Note: You should see Debug View opened and in Debug Console You should able to see "Connected to the target VM, address: '127.0.0.1:5005', transport: 'socket'"

  5. Put breakpoints in few test cases in your Testclass.

  6. Come to Terminal where you run "sbt -jvm-debug 5005" and run like below

    project <your-module-name>
    it:testOnly package.TestSpec
    

    For example: com.myproject.module.AddServiceTest[Spec]

  7. You can see debug started in your test case breakpoint.

⒈起吃苦の倖褔 2024-10-08 12:06:57

我从发布的答案中了解了每一步,但它是不同答案的组合:

  1. 转到文件> >设置> SBT 将行 -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 粘贴到 VM 参数框中已有的内容之后
  2. sbt -jvm-debug 5005 testOnly myTestcase
  3. Run >附加到进程

I learned every step from the posted answers but it's a combination of different answers:

  1. Go to File > Settings > SBT Paste the line -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 in the VM parameters box, after the ones that are already there
  2. sbt -jvm-debug 5005 testOnly myTestcase
  3. Run > Attach to process
泼猴你往哪里跑 2024-10-08 12:06:57

根据上面 Roberto Tyley 的回答,但在 Windows 中我们还需要在安装 sbt 后设置以下环境变量:

SBT_HOME
C:\Program Files (x86)\sbt\
[或安装 sbt 的任何位置]

SBT_OPTS
-Xdebug -runjdwp:transport=dt_socket,server=y,suspend=n,address=5005

[per RT's IntelliJ example]

添加到路径:%SBT_HOME%\bin;%SBT_OPTS%

然后运行以下命令在项目文件夹内的命令行中
“sbt 运行 -jvm -debug 5005”。

如果工作正常,命令行将首先输出一行 re
“侦听地址:5005 处的传输 dt_socket”。

在 IntelliJ 中设置断点。

在浏览器中打开网站以触发调试器断点,例如“http://localhost:9000/”。

As per Roberto Tyley's answer above, but in Windows we also need to set the following environment variables after installing sbt:

SBT_HOME
C:\Program Files (x86)\sbt\
[or wherever sbt is installed]

SBT_OPTS
-Xdebug -runjdwp:transport=dt_socket,server=y,suspend=n,address=5005

[per RT's IntelliJ example]

Add to path: %SBT_HOME%\bin;%SBT_OPTS%

Then run the following in the command line within the project folder
"sbt run -jvm -debug 5005".

If this is working properly, the command line will initially output a line re
"Listening for transport dt_socket at address: 5005".

Set breakpoint in IntelliJ.

Open website in browser to trigger the debugger breakpoint e.g. "http://localhost:9000/".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文