简体   繁体   English

如何通过逆时针(或la clojure)运行/调试compojure web应用程序

[英]How to run/debug compojure web app via counterclockwise (or la clojure)

I'm trying to write my first web app in compojure. 我正在尝试用compojure编写我的第一个Web应用程序。 I'm using ccw, and I File-New-Project, Clojure Project and use the "compojure" leiningen template. 我正在使用ccw,我使用File-New-Project, Clojure Project并使用“compojure”leiningen模板。 End up with project.clj looking like 最终看起来像project.clj

(defproject asdf "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :dependencies [[org.clojure/clojure "1.4.0"]
                 [compojure "1.1.5"]]
  :plugins [[lein-ring "0.8.2"]]
  :ring {:handler asdf.handler/app}
  :profiles
  {:dev {:dependencies [[ring-mock "0.1.3"]]}})

src/asdf/handler.clj looks like src / asdf / handler.clj看起来像

(ns asdf.handler
  (:use compojure.core)
  (:require [compojure.handler :as handler]
            [compojure.route :as route]))

(defroutes app-routes
  (GET "/" [] "Hello World")
  (route/not-found "Not Found"))

(def app
  (handler/site app-routes))

I found I can run this using lein ring server from the command line, but I'm not sure how to run this from eclipse. 我发现我可以从命令行使用lein ring server来运行它,但是我不知道如何从eclipse运行它。 I'm of course hoping to be able not only to run it, but also to debug it and set breakpoints and such. 我当然希望不仅能够运行它,还能调试它并设置断点等。 Is there a way to do this in eclipse? 在eclipse中有没有办法做到这一点? Or, if not, how about IntelliJ/La-Clojure? 或者,如果没有,IntelliJ / La-Clojure怎么样? (I'm a bit afraid of emacs, for now, but maybe if it's super-simple I'd give it a try). (我现在有点害怕emacs,但也许如果它超级简单我会尝试一下)。

Or, is this just not the typical development process for a compojure app? 或者,这不是一个compojure应用程序的典型开发过程吗? (If not, what is? Just run lein ring server and pray?) (如果没有,那是什么?只要运行lein ring server并祈祷?)

If it makes a difference this is on Win7. 如果它有所作为,这是在Win7上。

Here's a recipe that's work great for me while developing Ring applications: 这是一个在开发Ring应用程序时非常适合我的配方:

  • Ensure you have leiningen support properly configured for your projet (do it once if in doubt): 确保为您的项目配置了正确的leiningen支持(如果有疑问,请执行一次):
    • in the package explorer, select the project, and invoke the contextual command Leiningen > Reset configuration 在包资源管理器中,选择项目,然后调用上下文命令Leiningen > Reset configuration
    • then also invoke the Leiningen > Update dependencies command 然后还调用Leiningen > Update dependencies命令
    • you should see a Leiningen Dependencies virtual node in your project, referencing the direct and transitive dependencies of your project 您应该在项目中看到Leiningen Dependencies虚拟节点,引用项目的直接和传递依赖项
  • Select the asdf.handler file, right click and then Debug as > Clojure Application 选择asdf.handler文件,右键单击,然后选择Debug as > Clojure Application
  • Open the asdf.handler namespace in an editor 在编辑器中打开asdf.handler命名空间
  • With the cursor currently still in the editor, type Ctrl+Alt+N to jump to the REPL and switch the REPL's current namespace to asdf.handler at the same time 当光标当前仍在编辑器中时,键入Ctrl+Alt+N以跳转到REPL并同时将REPL的当前命名空间切换为asdf.handler
  • Start the app by typing (app) + Enter (or Ctrl+Enter if your cursor is not at the end of the line) 键入(app) + Enter启动应用(app) (如果光标不在行尾, Ctrl+Enter

You can now navigate between the editors and the REPL. 您现在可以在编辑器和REPL之间导航。

  • To send editor content to the REPL, select it, and hit Ctrl+Enter 要将编辑器内容发送到REPL,请选择它,然后Ctrl+Enter
  • If you hit Ctrl+Enter without a selection, the whole 'top level expression' (eg a defn) will be sent to the REPL 如果你没有选择Ctrl+Enter ,整个'顶级表达式'(例如一个defn)将被发送到REPL
  • To resend the whole file to the REPL, type Ctrl+Alt+S 要将整个文件重新发送到REPL,请键入Ctrl+Alt+S
  • the whole list of keyboard shortcuts specific to CCW is here: http://code.google.com/p/counterclockwise/wiki/EditorKeyBindingsFeatures 特定于CCW的键盘快捷键列表如下: http//code.google.com/p/counterclockwise/wiki/EditorKeyBindingsFeatures

Note that a future version of Counterclockwise will integrate a little bit more with Leiningen 2, but as it currently stands, the very nature of developing ring applications make it not so painful to bootstrap things as described above, IMHO 请注意,未来版本的Counterclockwise将与Leiningen 2集成更多一点,但是就目前而言,开发ring应用程序的本质使得如上所述的引导程序并不那么痛苦,恕我直言

You can run Compojure/Ring apps on IntelliJ IDEA and La Clojure with the following steps: 您可以使用以下步骤在IntelliJ IDEA和La Clojure上运行Compojure / Ring应用程序:

  1. Generate pom.xml from leiningen's project.clj using lein pom command. 使用lein pom命令从leiningen的project.clj生成pom.xml
  2. Import maven project with IntelliJ IDEA as usual. 像往常一样使用IntelliJ IDEA导入maven项目。 You might want to make sure that you have Clojure jar in classpath. 您可能希望确保在类路径中有Clojure jar。
  3. Once the project is loaded, you can start Clojure REPL using Tools -> Start Clojure Console. 加载项目后,您可以使用工具 - >启动Clojure控制台启动Clojure REPL。
  4. To load a Clojure file to REPL, select Tools -> Clojure REPL -> Load file to REPL. 要将Clojure文件加载到REPL,请选择工具 - > Clojure REPL - >将文件加载到REPL。

After that, to start a Ring app you can just load a Clojure file that invokes ring.adapter.jetty/run-jetty . 之后,要启动Ring应用程序,您只需加载调用ring.adapter.jetty/run-jetty的Clojure文件ring.adapter.jetty/run-jetty

The code to run a simple route on http://localhost:4004/ would look like this: http://localhost:4004/上运行简单路由的代码如下所示:

(require 'compojure.core)
(require 'ring.adapter.jetty)

(ring.adapter.jetty/run-jetty
  (compojure.core/routes (compojure.core/ANY "/" [] "Hello world!"))
  {:port 4004 :join? false})

:join? option is important, if it would be set to true (the default), the REPL would not accept more commands. 选项很重要,如果将其设置为true(默认值),则REPL将不接受更多命令。 Your routes will usually be more complex and compojure.core/defroutes or other means should be used. 您的路线通常会更复杂,并且应该使用compojure.core/defroutes或其他方法。

You can put such file in test path, so it wouldn't be loaded when running the project outside of IDEA. 您可以将此类文件放在test路径中,因此在IDEA之外运行项目时不会加载它。 If Clojure facet is not added to your module, you can add it in File -> Project Structure -> Modules. 如果Clojure facet未添加到您的模块中,您可以将其添加到文件 - >项目结构 - >模块中。

A complete sample (with jetty reloading) is available here: https://github.com/tlipski/ganelon-demo - development is done with IDEA and real site runs on Heroku: http://ganelon.herokuapp.com . 这里有一个完整的样本(有码头重新加载): https//github.com/tlipski/ganelon-demo - 使用IDEA进行开发,在Heroku上运行真实站点: http//ganelon.herokuapp.com

Debugging Clojure apps run with the technique above is possible as well - you just have to: 调试使用上述技术运行的Clojure应用程序也是可行的 - 您只需:

  1. Create Remote debugging Run profile in IntelliJ IDEA 创建远程调试在IntelliJ IDEA中运行配置文件
  2. Add apropriate JVM options from a profile above (eg agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 ) to REPL settings in File -> Project Structure -> Modules -> [your module] -> Clojure facet -> JVM Arguments field. 从上面的配置文件中添加适当的JVM选项(例如, agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 )到文件 - >项目结构 - >模块 - > [您的模块] - >中的REPL设置Clojure facet - > JVM Arguments字段。
  3. Start REPL with Tools -> Start Clojure Console. 使用工具启动REPL - >启动Clojure控制台。
  4. Start Remote debugging profile. 启动远程调试配置文件

After that, you can add breakpoints, inspect variables, etc. 之后,您可以添加断点,检查变量等。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使Clojure Compojure应用通过Docker容器中的已编译jar无头运行? - How to get Clojure Compojure app to run headless via compiled jar within Docker container? 如何将多个Clojure Web(Compojure)应用程序合并为一个? - How to merge several Clojure Web (Compojure) applications into one? 如何在带有逆时针方向的Eclipse中使用已编译的Clojure类 - How to use a compiled Clojure class in Eclipse with Counterclockwise 如何在Eclipse / CounterClockWise中重新格式化/重新生成Clojure代码? - How to reformat/reindent Clojure code in Eclipse/CounterClockWise? 如何将clojure Web应用程序部署到Amazon EC2(AWS Elastic Beanstalk + Leiningen + Compojure + Ring + Tomcat) - How to deploy a clojure web application to Amazon EC2 (AWS Elastic Beanstalk + Leiningen + Compojure + Ring + Tomcat) 如何在Clojure + Compojure + Ring Web应用程序中重用/包括现有的Java servlet和过滤器? - How to reuse/include existing java servlets and filters in Clojure + Compojure + Ring Web application? Clojure:如何在Clojure / Compojure中使用Jquery实现搜索建议功能 - Clojure: How to implement a search suggestion functionality with Jquery in Clojure/Compojure 如何在Intellij中调试Clojure Web应用程序? - How to debug a Clojure web application in Intellij? 在Clojure中使用逆时针编译问题 - Problems compiling in clojure with Counterclockwise 在日食中运行clojure(逆时针) - running clojure in eclipse (counterclockwise)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM