Unable to start up compojure server [duplicate] - clojure

I'm attempting to run the boilerplate project from lein new compojure clojure-lice.
When I run lein ring server I receive the following lovely error:
Exception in thread "main" java.lang.RuntimeException: No reader function for tag namespace
My project.clj
(defproject clojure-lice "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:min-lein-version "2.0.0"
:dependencies [[org.clojure/clojure "1.8.0"]
[compojure "1.5.1"]
[ring/ring-defaults "0.2.1"]]
:plugins [[lein-ring "0.9.7"]]
:ring {:handler clojure-lice.handler/app}
:profiles
{:dev {:dependencies [[javax.servlet/servlet-api "2.5"]
[ring/ring-mock "0.3.0"]]}})
My core.clj:
(ns clojure-lice.handler
(:require [compojure.core :refer :all]
[compojure.route :as route]
[ring.middleware.defaults :refer [wrap-defaults site-defaults]]))
(defroutes app-routes
(GET "/" [] "Hello World")
(route/not-found "Not Found"))
(def app
(wrap-defaults app-routes site-defaults))
My system stats:
java version "9.0.1"
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)
Leiningen 2.8.0 on Java 9.0.1 Java HotSpot(TM) 64-Bit Server VM
Clojure 1.8.0
OSX 10.12.6

Try downgrading Leiningen to 2.7.1:
lein upgrade 2.7.1
This is a regression in Leiningen 2.8.0. See https://github.com/technomancy/leiningen/issues/2328.

Related

clj repl crashing when launched and pwd is ~

clj repl crashing when launched and pwd is ~, otherwise from any other directory it's fine.
I installed clojure following instructions from
https://clojure.org/guides/getting_started#_installation_on_linux
However, when i launch the repl staying in ~, I get following
Exception in thread "main" java.lang.IllegalStateException: Attempting to call unbound fn: #'clojure.main/main
at clojure.lang.Var$Unbound.throwArity(Var.java:45)
at clojure.lang.AFn.invoke(AFn.java:28)
at clojure.lang.AFn.applyToHelper(AFn.java:152)
at clojure.lang.AFn.applyTo(AFn.java:144)
at clojure.lang.Var.applyTo(Var.java:705)
at clojure.main.main(main.java:40)
And if i change the directory to any other location, it runs ok
:~/src$ clj
Clojure 1.10.3
user=>
My OS is a Debian Buster (Minimal)... I tried looking up, but to no avail...I also have no clue as to what to look for...
Not sure if following is of any help...
:~$ mvn --version
Apache Maven 3.6.0
Maven home: /usr/share/maven
Java version: 11.0.11, vendor: Debian, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_IN, platform encoding: UTF-8
OS name: "linux", version: "4.19.0-17-amd64", arch: "amd64", family: "unix"
:~$ java --version
openjdk 11.0.11 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+9-post-Debian-1deb10u1)
OpenJDK 64-Bit Server VM (build 11.0.11+9-post-Debian-1deb10u1, mixed mode, sharing)
The cause of the behavior is explained in one of the comments by Sean Corfield on Clojure Q&A.

leiningen uberjar - add external jar at runtime

I am trying to see how I can add a directory and an external jar to the classpath when making a leiningen uberjar.
The reason is that I need to distribute a jar but some dependencies (jdbc driver for example) cannot be compiled into the uberjar due to licencing restrictions.
I would also like to provide certain external resources such as properties for logging and configuration external to the jar.
Normally in java or spring boot I would use the appropriate command line option to change the classpath. However -cp does not find the jar etc
Is there a way to do this or an appropriate plugin?
Thanks in advance
You can add the jar as a resource in the :dev profile. Then it is added to the classpath. The dev profile is for the local development and not packaged into the uberjar.
:profiles {
:uberjar {:aot :all}
:dev {:resource-paths ["no-redist/commercial-jdbc-driver.jar"]}}
At 'production' time with the uberjar you need set the classpath then manually:
java -cp no-redist/commercial-jdbc-driver.jar;your-app-uber-jar.jar main.namespace
Afaik when using the -jar flag, it uses the dependencies in the jar file, whatever is linked and referred to in there. Combining -cp and -jar might not work.
Another way is to refer to the no-distributable jar file in the jar manifest (META-INF/MANIFEST.MF):
Class-Path: no-redist/commercial-jdbc-driver.jar
The the java -jar your-app-uber-jar.jar would look for the jar in the folder no-redist/commercial-jdbc-driver.jar in the local directory. Add this in leinigen like:
:manifest {"Class-Path" "no-redist/commercial-jdbc-driver.jar"}

Running a another task when an uberjar is created with Leiningen

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.

How to compile namespace in remote REPL

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).

:repl-options dont reflect in the ritz nrepl client in emacs

I am using the :repl-options key in my project.clj to load default options when I start repl using lein2 repl.
I have added ritz plugins to my project.clj and ~/.lein, and once I start the repl using -
a) lein2 repl
and then connect to it using
b) M-x nrepl RET Host: localhost RET Port: 5332 (Port number on which nrepl started in the first step)
The ns that I load using :repl-options are avalaible in the repl that starts using lein2 repl, however they are not avalaible in the client started using M-x nrepl.
Any ideas on how do I get them in the client started by M-x nrepl too ?
Frankly I think that it is best to ask Leiningen related questions on its mailing list. I had an issue with Leiningen recently and Phil Hagelberg, developer of the tool, responded almost instantly.
You could also ask about https://stackoverflow.com/questions/12493003/unmateched-delimiter-exception-but-still-able-to-run-code. I have similar issues with Lein2 (only in Cygwin), so maybe it will result in a bug report.