How To Run Lein Ring Server Command From Eclipse? - eclipse

I'm trying to figure out how to run lein ring server for a Clojure Ring and Compojure application in Eclipse Mars with Counterclockwise on Windows.
I've added the correct dependencies to my project.clj file. Running this command from a command line works without any trouble.
However, if I type it into the repl inside eclipse I get the error : "CompilerException java.lang.RuntimeException: Unable to resolve symbol: lein in this context"
Is there a way to run lein ring server from within Eclipse?
I'm very new to Clojure development and hoping I'm just missing something simple here.

You can run lein commands like this http://doc.ccw-ide.org/documentation.html#lein-generic-launcher .
Trying to run lein commands in repl is wrong as leiningen is build tool, and works like any other console program.
If you want to start ring server from repl you can, to do that you need to switch to namespace where you start ring server and start it, by evaluating server start code in repl. It's described at ring wiki https://github.com/ring-clojure/ring/wiki/Getting-Started , in the pretty much like this
(run-jetty handler {:port 3000})
Also I suggest to take a look at https://github.com/plexus/chestnut (app template) so your start server from repl will look like this
(run-web-server)
assuming you have method like this
(defn run-web-server [& [port]]
(let [port (Integer. (or port (env :port) 10555))]
(println (format "Starting web server on port %d." port))
(run-jetty http-handler {:port port :join? false})))

Related

Unable to start Ensime debugger in Emacs

I am using Emacs 24.5.1 scala 2.11.5 with ensime. Ensime server runs fine with all error suggestion and other IDE feature etc. But when I start debugging code with M-x ensime-db-attach it prompt with me Hostname and Port. Which port is it asking for? I want to debug my code locally.
Executing sbt -jvm-debug 5005 from scala home directory resolved the problem. Also in Emacs M-x ensime-db-attach when prompted let Hostname be localhost and Port be 5005.
I'm assuming that you have used
sbt ensimeConfig
And in Emacs, you've started the Ensime server. What you need to do, is start an sbt session. And in the sbt console, you invoke
ensimeRunDebug fibonacci.Solution
(If you have a package fibonacci and a class called Solution.) This hangs on the console.
You then need to go to your Emacs buffer for your source code with the ENSIME menu and put a breakpoint in. You'll get a message that the message is being queued.
Then attach to the debugger - if you use the ENSIME menu, use the Debugger sub-menu and Attach. You'll need to give the hostname and port. Usually, localhost and port 5005.
This should send the breakpoint and run the program. You'll then be debugging.

Why is cider-jack-in hanging in emacs

I'm working through the following tutorial on Clojure. I've just installed both Emacs and Leiningen. If invoked separately, both work. However, when I am trying to invoke cider-jack-in, as described in the tutorial:
Using Emacs, open the file clojure-noob/src/clojure_noob/core.clj,
which you created in Chapter 1. Next, use M-x cider-jack-in. This
starts the REPL and creates a new buffer where you can interact with
it.
that hangs forever after the last message:
Starting nREPL server via lein repl :headless...
You can run the command `cider-jack-in' with C-c M-j
Starting nREPL server via lein repl :headless...
What am I doing wrong?
Edit: To solve the problem, I upgraded leiningen from 1.7 (that's what apt-get installed) to 2.6.1.
Recently cider changed so you no longer need to add things to ~/.lein/profiles.clj to install cider-nrepl and clj-refactor. Cider will take care of that now. You should remove that part from your config.
In general for these situations it help to run lein from the command line first and make sure it can actually get the projects dependencies. Most of the times it's sitting there downloading a jar file at 3 bytes per second and not actually stalled. Other times it's failing with SSL/TLS certificate validation problems.

Clojure - start a REPL without a project.clj

I started using Clojure with leiningen (and now boot).
Now I sometimes want to get quickly to a Clojure{Script} CIDER REPL in Emacs to execute just a few instructions. I don't want to create a project.clj file for that, since I just want a throwaway REPL.
Is there a way to get a Clojure REPL, for instance in the *scratch* buffer ?
well, you can execute M-x cider-jack-in anywhere you want, even with no project.clj in path. This works for me.
You can just type lein repl in the friendly console / shell / terminal right next to you -- no project.clj required. This will start a REPL as expected, to which you can then connect from Emacs via M-x cider-connect (which in recent versions will handily suggest host and port to connect to).
M-x cider-jack-in basically does the same thing (i.e. lein repl) behind the scenes.
I'm not a boot user, but according to the boot wiki for leiningen users it should be possible to call boot repl -s.
Use M-x cider-jack-in, and if you don't want it to warn you that you're running cider-jack-in without a Clojure project, add the following to your emacs.d/init.el:
(setq cider-allow-jack-in-without-project t)

print output of execution in cider repl

I am wondering if there is a way to have the output of the current execution in emacs cider when using cider-connect.
For instance :
I run lein repl on a project directory
then connect to it in emacs using cider-connect.
Now let's say that I have (println "cider is amazing by the way") in the code of one of my ring handlers, this will only be printed in the console I ran lein repl when a request is made.
How can I have this output also in my nrepl buffer ?
Sorry to say, I suspect that you cannot do this in the way you describe. The output is going strait to the console of that device and not through anything related to nrepl on the way. This also makes sense if you consider that nrepl is often not even running on the same computer. (the "n" in nrepl is for "network").
Perhaps you can arrange for that output to be teed to a file where you can get at it? Then you could start a thread on your nrepl buffer that cated that file. Or have a buffer in emacs that watches the remote file.
If you start leiningen via cider-jack-in you should get the output in the repl buffer.
One way to use this with a remote setup could be to call C-u M-x cider-jack-in and use a specialized server command that will essentially trigger the lein repl command (say over ssh) on the remote machine -- I haven't checked whether this will actually work, but I don't see any reason why it shouldn't. If you can access the code over tramp, it shouldn't matter much whether the code is remote or not.

Emacs with Slime and Swank for non-leiningen projects

I found this website which explains how to use emacs with leiningen, swank, and slime. Is there a way to use slime + swank in non-leiningen projects i.e. how can I connect to slime/swank repl to run a ad-hoc Clojure script while I write it as demonstrated here?
You need to have swank-clojure.jar in CLASSPATH and your script should have following code:
(require 'swank.swank)
(swank.swank/start-repl 4005)
to start swank process on port 4005 (or some other)...
P.S. You can look onto Incanter's swank script, that pass this code in environment variable, and later it evaluated as part of boostrap script