[英]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应用程序时非常适合我的配方:
Leiningen > Reset configuration
Leiningen > Reset configuration
Leiningen > Update dependencies
command Leiningen > Update dependencies
命令 Leiningen Dependencies
virtual node in your project, referencing the direct and transitive dependencies of your project Leiningen Dependencies
虚拟节点,引用项目的直接和传递依赖项 asdf.handler
file, right click and then Debug as > Clojure Application
asdf.handler
文件,右键单击,然后选择Debug as > Clojure Application
asdf.handler
namespace in an editor asdf.handler
命名空间 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
(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之间导航。
Ctrl+Enter
Ctrl+Enter
Ctrl+Enter
without a selection, the whole 'top level expression' (eg a defn) will be sent to the REPL Ctrl+Enter
,整个'顶级表达式'(例如一个defn)将被发送到REPL Ctrl+Alt+S
Ctrl+Alt+S
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应用程序:
pom.xml
from leiningen's project.clj
using lein pom
command. lein pom
命令从leiningen的project.clj
生成pom.xml
。 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应用程序也是可行的 - 您只需:
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. agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
)到文件 - >项目结构 - >模块 - > [您的模块] - >中的REPL设置Clojure facet - > JVM Arguments字段。 After that, you can add breakpoints, inspect variables, etc. 之后,您可以添加断点,检查变量等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.