我正在使用 Intellij + Cursive,我想调试使用 ring + compojure 编写的 Clojure Web 应用程序。我使用 lein 和 ring 插件在 Intellij 终端中启动应用程序:
> lein ring server-headless
我想使用 Intellij 调试这个应用程序,在源代码中设置断点,查看变量等。
但是 Intellij 的 Leiningen 选项卡没有显示带有 ring 命令的任务。运行配置也没有运行 ring 命令的选项。
我正在使用 Intellij + Cursive,我想调试使用 ring + compojure 编写的 Clojure Web 应用程序。我使用 lein 和 ring 插件在 Intellij 终端中启动应用程序:
> lein ring server-headless
我想使用 Intellij 调试这个应用程序,在源代码中设置断点,查看变量等。
但是 Intellij 的 Leiningen 选项卡没有显示带有 ring 命令的任务。运行配置也没有运行 ring 命令的选项。
Intellij 有一个可以与 Clojure 一起使用的远程调试运行配置。
首先在文件中的jvm中添加以下选项project.clj:
:jvm-opts ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5010"]
其中 5010 是要在 Intellij 远程调试配置中指定的端口号。
然后,在 Intellij 中,转到Run -> Run... -> Edit Configurations...使用 + 按钮并选择Remote.为配置命名,将端口更改为 5010,然后单击确定。使用 lein 运行应用程序:
> lein ring server-headless
应用程序运行后,运行(在 Intellij 中)您创建的 Intellij 远程调试配置。您将能够设置断点、逐行运行等。
没有莱宁根
另一种选择是删除 leiningen 并将 ring 应用程序作为 Cursive 中的 Clojure 应用程序运行。您必须添加一个-main功能:
(defn -main [] (run-jetty app {:port 8080})
app是您在其中定义路由并用作环处理程序:ring {:handler xxx/app}的功能project.clj.您必须在 Intellij 中要求[ring.adapter.jetty :refer [run-jetty]]和调试文件作为 Clojure 应用程序。
你需要两个步骤:
project.clj的传递额外的参数,像这样 :ring {:nrepl {:start? true :port 4001} ;; <== Add this
:handler com.mycompany.web/myhandler} ;; you should have this
...这应该在端口 4000 中启动 Web 应用程序,并在端口 4001 中启动用于调试的 nREPL 端口等。您可以查看lein-ring 文档以获取更多详细信息。
启动应用程序时,您应该看到以下内容:
$ lein ring server-headless 4000
[... some output omitted ...]
Started nREPL server on port 4001
Started server on port 4000
localhost0.0.0.0