I would like to start a server like this:
lein ring server 3000 local
lein ring server 3000 test
where local or test could be read by my app to run with different env. How can I do that?
Your use-case is exactly what Leiningen profiles are for. For example
lein with-profile test ring server
Related
I have created a ClojureScript project using:
lein new re-frame my-project
I've then opened it in IntelliJ using Cursive. In the terminal after typing lein dev, it prompts me with the message:
shadow-cljs - HTTP server available at http://localhost:8280
shadow-cljs - server version: 2.8.52 running at http://localhost:9630
shadow-cljs - nREPL server started on port 8777
shadow-cljs - watching build :app
[:app] Configuring build.
[:app] Compiling ...
[:app] Build completed. (203 files, 1 compiled, 0 warnings, 3.65s)
I can open the server using the link which directs me to a REPL, but not the nREPL connected to the browser. Following their documentation I type shadow-cljs clj-repl in to another terminal, which opens a REPL but not one that is connected to my browser or project. If I type (js/alert "hi m8") in to the REPL it responds:
Syntax error compiling at (REPL:2:1).
No such namespace: js
My question is, is how do I use the nREPL it says has started and preferably how do I access it in the integrated REPL in IntelliJ?
Thanks.
Update
Have got it working as below but if anyone knows how to get it working here in Cursive / IntelliJ:
That would be super.
The nREPL connection will always start out in Clojure mode. You can switch it to use CLJS by calling (shadow.cljs.devtools.api/repl :app) and return to Clojure mode via :cljs/quit.
You should however be connecting to a "Clojure REPL" -> "Remote" and then "localhost" with port 8777. This is configured as the default in the re-frame template via shadow-cljs.edn :nrepl {:port 8777}.
The screenshot you posted looks like you connected to the random port lein created. This will also work but requires additional configuration for the nREPL middleware.
I figured it. You have to use shadow-cljs cljs-repl app in another terminal.
When the uberjar is created, I also need to run lein deps. How do I make Leiningen automatically run lein deps when lein uberjar is run?
lein deps is run automatically on other lein tasks like run jar cljsbuild...
In fact I never use lein depsexcept in lein do clean, deps.
Note : I am just transitioning to boot myself, but composing tasks is much easier with this build tool.
You can have leiningen run a combination of any lein tasks via the do command. We can then define an alias to run the desired tasks with ease. In your profile.clj include the following:
:aliases {"build-with-deps" ["do" "clean" "deps" "uberjar"]}
Then whenever you call lein build-with-deps it will actually run the following: lein do clean, deps, uberjar.
I recommend reading through the sample project.clj provided by leiningen to better familiarize yourself with the capabilities of aliases.
Is there any way to run few clustered immutant2 based apps with no deploy to wildfly? I would like to test distributed cache having two REPLs opened but I see no option in immutant docs to have these 2 sessions in 1 cluster.
Looks like for immutant 1.x it was --clustered option for lein.
For Immutant 2, clustering is only available when running inside of WildFly. However, you can still get a repl inside WildFly - just create a "dev" war with the lein-immutant plugin, and it will start a repl for you when deployed to WildFly. You create a dev war with:
lein immutant war --dev
(assuming you are using [lein-immutant "2.0.0"]. See the WildFly guide for instructions on starting a WildFly instance in clustered mode.
I have a problem compiling .clj files which reside in a project where I run the nREPL server process:
I've created a new project using lein new xxx.
In the project folder I started up an nREPL by lein repl.
In another terminal window I started a client lein repl :connect localhost:12345/repl.
I created a simple namespace file and saved it inside the project in the appropriate location:
(ns remote.one)
(def foo 42)
Now on the client terminal I called this function
(compile 'remote.one)
I've got the below exception:
CompilerException java.lang.ClassNotFoundException: remote.one, compiling:(C:\Users\xxx\AppData\Local\Temp\form-init2429492334116477513.clj:1:1)
Now I would have expected the compile call to be executed in the server not on the client. Can it be done at all?
Thanks
I just tried it and it worked for me. What happened the first time I tried it was that I missed a step: setting the current directory as the project's. I see that this step is also missing from your description, maybe that's the reason it doesn't work in your case.
Create a new project using lein new remote.
Change the current directory cd remote.
Start the nREPL server from the project folder with lein repl :headless (which I realize now is also different from your description).
Open a new console and start the nREPL client lein repl :connect localhost:port/repl in ~/..
Create the file for the ns in ~/remote/src/remote/one.clj.
From the client evaluate (compile 'remote.one).
(Using Leiningen 2.3.4 on Java 1.7.0 Java HotSpot(TM) 64-Bit Server VM and Clojure 1.5.1).
When I launch a webapp with lein run or lein ring server, I get two processes: Leiningen itself, and my app. When I terminate the session with Ctrl+C, it terminates Leiningen and leaves my app running.
How can I terminate both processes or prevent Leiningen from spawning a process?
This sounds like https://github.com/technomancy/leiningen/issues/455 This issue is fixed on the Leiningen master branch, and also is backported to the 1.x series as 1.7.1.
What about running lein repl and then start the server by calling your main function from the REPL.