Hello, I'm using latest java and latest clojure tools, trying to load [ring.adapter.jetty :refer [run-jetty]] in deps: ring/ring-jetty-adapter {:mvn/version "1.12.2"} but got error -
2. Unhandled clojure.lang.Compiler$CompilerException
Error compiling ring/util/jakarta/servlet.clj at (1:1)
1. Caused by java.lang.ClassNotFoundException
jakarta.servlet.AsyncContext
what I'm doing wrong?clj -X:deps tree https://gist.github.com/faust451/6d3a7b351136aae5992deb591f4ec6d0
That class comes from org.eclipse.jetty.toolchain/jetty-jakarta-servlet-api and that dependency is on the classpath as reported by the last command.
But are you sure that the process where you see the exception is running with the same classpath? Meaning, it was restarted after any change to deps.edn, it doesn't use any aliases.
yes sure, I restarted clj -M:cider-clj:jvm-base
I'm connecting to nrepl
In the same process where the error happens, what does this output?
(->> (clojure.string/split (System/getProperty "java.class.path") #":")
(filter #(clojure.string/includes? % "jakarta")))/home/moon/.m2/repository/org/ring-clojure/ring-jakarta-servlet/1.12.2/ring-jakarta-servlet-1.12.2.jarThere should also be /home/moon/.m2/repository/org/eclipse/jetty/toolchain/jetty-jakarta-servlet-api/5.0.2/jetty-jakarta-servlet-api-5.0.2.jar, but it isn't, somehow.
I don't have better ideas here except trying to:
1. Run clj -Sdeps '{:deps {org.eclipse.jetty.toolchain/jetty-jakarta-servlet-api {:mvn/version "5.0.2"}}}' and execute (import 'jakarta.servlet.AsyncContext) to see what happens
2. Removing .cpcache directory at the root of the project
3. Checking what's inside /home/moon/.m2/repository/org/eclipse/jetty/toolchain/jetty-jakarta-servlet-api/5.0.2/, maybe removing the whole directory
clj -Sdeps '{:deps {org.eclipse.jetty.toolchain/jetty-jakarta-servlet-api {:mvn/version "5.0.2"}}}'
user=> (import 'jakarta.servlet.AsyncContext)
jakarta.servlet.AsyncContext/home/moon/.m2/repository/org/eclipse/jetty/toolchain/jetty-jakarta-servlet-api/5.0.2/
is in placeafter removing /home/moon/.m2/repository/org/eclipse/
and reinstall deps
ls /home/moon/.m2/repository/org/eclipse/jetty/
jetty-project/ jetty-server/ websocket/ What happens if you run you project not through CIDER but via plain clj?
by the way my output on starting clj looks:
clj -M:cider-clj:jvm-base
Warning: failed to load the S3TransporterFactory class
Warning: failed to load the S3TransporterFactory class
Warning: failed to load the S3TransporterFactory class
Warning: failed to load the S3TransporterFactory class
Warning: failed to load the S3TransporterFactory class
Warning: failed to load the S3TransporterFactory class
Warning: failed to load the S3TransporterFactory class
Warning: failed to load the S3TransporterFactory class
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See for further details.
Warning: failed to load the S3TransporterFactory class
Warning: failed to load the S3TransporterFactory class
Warning: failed to load the S3TransporterFactory class
Warning: failed to load the S3TransporterFactory class
nREPL server started on port 43081 on host localhost - What happens if you run you project not through CIDER but via plain clj? Sorry, could you clarify please?
I have seen this in the past, I don't remember what it was related to 🤔
this works fine on my box :
clj -Sdeps '{:deps {ring/ring-jetty-adapter {:mvn/version "1.12.2"}}}'
user=> (require '[ring.adapter.jetty :refer [run-jetty]])on my side:
Clojure 1.12.0
user=> (require '[ring.adapter.jetty :refer [run-jetty]])
Execution error (ClassNotFoundException) at java.net.URLClassLoader/findClass (REPL:-1).
jakarta.servlet.AsyncContextcan you paste the output of clj -Sdeps '{:deps {ring/ring-jetty-adapter {:mvn/version "1.12.2"}}}' -Spath ?
clj -X:deps tree |grep jakart
. org.ring-clojure/ring-jakarta-servlet 1.12.2
. org.eclipse.jetty.toolchain/jetty-jakarta-servlet-api 5.0.2
. org.eclipse.jetty.toolchain/jetty-jakarta-servlet-api 5.0.2ls /home/moon/.m2/repository/org/eclipse/jetty/toolchain/jetty-jakarta-servlet-api/5.0.2/
jetty-jakarta-servlet-api-5.0.2.jar jetty-jakarta-servlet-api-5.0.2.pom _remote.repositories
jetty-jakarta-servlet-api-5.0.2.jar.sha1 jetty-jakarta-servlet-api-5.0.2.pom.sha1I mean the full -Spath, not the -Stree
oh, but looks you are running that inside a folder with a deps.edn
try on a empty folder
what is the output of clj --version ?
clj --version
Clojure CLI version 1.12.0.1530hmmm that is weird, because for some reason it is loading clojure 1.11
and also all those Warning: failed to load the S3TransporterFactory class
i think 1.12.0 version of tools, but clojure version is 1.11
yes that strange
Warning: failed to load the S3TransporterFactory class
but the latest version of the cli should by default start with clojure 1.12
hm strange
so there is something weird with your clojure installation
just downloaded from https://download.clojure.org/install/
can you do a which clojure and then cat /path/to/clojure ?
which clojure
/gnu/store/59savh0mi0la9ri97cqck37drxlh9av1-profile/bin/clojureoh you are using guix
ls -l /gnu/store/59savh0mi0la9ri97cqck37drxlh9av1-profile/bin/clojure
lrwxrwxrwx 1 root root 81 Jan 1 1970 /gnu/store/59savh0mi0la9ri97cqck37drxlh9av1-profile/bin/clojure -> /gnu/store/d8c8vlbf3690r0p70qqinkgrfc9d4rqs-clojure-tools-1.12.0.1530/bin/clojureyes guix
what does clj -Sverbose shows?
clj -Sverbose
version = 1.12.0.1530
install_dir = /gnu/store/d8c8vlbf3690r0p70qqinkgrfc9d4rqs-clojure-tools-1.12.0.1530/lib/clojure
config_dir = /home/moon/.clojure
config_paths = /gnu/store/d8c8vlbf3690r0p70qqinkgrfc9d4rqs-clojure-tools-1.12.0.1530/lib/clojure/deps.edn /home/moon/.clojure/deps.edn deps.edn
cache_dir = /home/moon/.clojure/.cpcache
cp_file = /home/moon/.clojure/.cpcache/1083142194.cpand the output of cat /gnu/store/d8c8vlbf3690r0p70qqinkgrfc9d4rqs-clojure-tools-1.12.0.1530/lib/clojure/deps.edn
cat /gnu/store/d8c8vlbf3690r0p70qqinkgrfc9d4rqs-clojure-tools-1.12.0.1530/lib/clojure/deps.edn
{
:paths ["src"]
:deps {
org.clojure/clojure {:mvn/version "1.12.0"}
}
:aliases {
:deps {:replace-paths []
:replace-deps {org.clojure/tools.deps.cli {:mvn/version "0.11.78"}}
:ns-default clojure.tools.deps.cli.api
:ns-aliases {help }}
:test {:extra-paths ["test"]}
}
:mvn/repos {
"central" {:url " "}
"clojars" {:url " "}
}
} weird, it says 1.12.0 for clojure, as it should be
what is in /home/moon/.clojure/deps.edn ?
cat /home/moon/.clojure/deps.edn
{
:aliases {
;; Add cross-project aliases here
}
}to start with I have no idea where is the clojure 1.11 coming from
if you just do clj on an empty folder, I have :
clj
Clojure 1.12.0
user=> but not in my case )
clj
Clojure 1.11.1
user=> and what about running just clojure
clojure
Clojure 1.11.1
user=> dang
what if you remove your .m2/repository/org/clojure/ folder?
and also your /home/moon/.clojure/.cpcache
just to start from zero
when you run clj, it should go and download clojure 1.12
rm -rf ~/.m2/repository/org/clojure/
moon@antelope ~/code/test [env]$ rm -rf ~/.clojure/.cpcache
moon@antelope ~/code/test [env]$ clj
Warning: failed to load the S3TransporterFactory class
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See for further details.
Downloading: org/clojure/clojure/1.11.1/clojure-1.11.1.pom from central
Warning: failed to load the S3TransporterFactory class
Warning: failed to load the S3TransporterFactory class
Downloading: org/clojure/core.specs.alpha/0.2.62/core.specs.alpha-0.2.62.pom from central
Downloading: org/clojure/spec.alpha/0.3.218/spec.alpha-0.3.218.pom from central
Downloading: org/clojure/pom.contrib/1.1.0/pom.contrib-1.1.0.pom from central
Downloading: org/clojure/pom.contrib/1.1.0/pom.contrib-1.1.0.pom from central
Warning: failed to load the S3TransporterFactory class
Warning: failed to load the S3TransporterFactory class
Warning: failed to load the S3TransporterFactory class
Downloading: org/clojure/clojure/1.11.1/clojure-1.11.1.jar from central
Downloading: org/clojure/spec.alpha/0.3.218/spec.alpha-0.3.218.jar from central
Downloading: org/clojure/core.specs.alpha/0.2.62/core.specs.alpha-0.2.62.jar from central
Clojure 1.11.1
user=> I'm sorry guys )
haha that is so weird
yes crazy )
what about running clj -Strace
it should generate a trace.edn file
https://gist.github.com/faust451/74c3ce3ce895d4802f117475ad22cd2d
dang
and what if you run with the full path /gnu/store/d8c8vlbf3690r0p70qqinkgrfc9d4rqs-clojure-tools-1.12.0.1530/lib/clojure
maybe there is something weird with the PATH resolution
ls /gnu/store/d8c8vlbf3690r0p70qqinkgrfc9d4rqs-clojure-tools-1.12.0.1530/lib/clojure
deps.edn example-deps.edn libexec/ tools.ednI mean, what happens is you run that with the full path
ls -l /gnu/store/59savh0mi0la9ri97cqck37drxlh9av1-profile/bin/clojure
lrwxrwxrwx 1 root root 81 Jan 1 1970 /gnu/store/59savh0mi0la9ri97cqck37drxlh9av1-profile/bin/clojure -> /gnu/store/d8c8vlbf3690r0p70qqinkgrfc9d4rqs-clojure-tools-1.12.0.1530/bin/clojure
moon@antelope ~/code/test [env]$ /gnu/store/d8c8vlbf3690r0p70qqinkgrfc9d4rqs-clojure-tools-1.12.0.1530/bin/clojure
Clojure 1.11.1
user=> can you paste me the contents of that file /gnu/store/d8c8vlbf3690r0p70qqinkgrfc9d4rqs-clojure-tools-1.12.0.1530/bin/clojure
https://gist.github.com/faust451/2f06ff5c5fd5d4d64f2984a3ad35a4cf
one weird thing is that our scripts are different
might be something wrong with the package definition there is no package in guix for latest clojure-tools so i changed abit the definition of existing package
(define clojure-tools
(package
(inherit clj:clojure-tools)
(version "1.12.0.1530")
(source (origin
(method url-fetch)
(uri (string-append ""
version
".tar.gz"))
(sha256 (base32 "0jgd0lki1mml7ppccxnbhj9jbpy5cy3s11775p9kkfi6h654pwhg")))))) just changed version
oh, so that is probably it
but not sure what that inherit does
I never used guix
just inherit all properties from old package
and what are those?
https://gist.github.com/faust451/ca73af41a59b542119afc19ac1dbbbb3
because for example, the clojure script I'm using has a line inside that defines the tools classpath :
...
tools_cp="$install_dir/libexec/clojure-tools-$version.jar"
...and yours has a bunch of jars but no even a reference to clojure-tools
if I'm installing via
sudo ./linux-install.sh --prefix /opt/infrastructure/clojure
then I got error
~/code/tools/clojure/bin/clojure
Error: Could not find or load main class clojure.main
Caused by: java.lang.ClassNotFoundException: clojure.mainhow I can work around?
but what if you run /opt/infrastructure/clojure/bin/clojure
oh sorry
sudo ./linux-install.sh --prefix ~/code/tools/clojureI'm not following, you are installing it to /opt/infrastructure but then running it from some other place
oh ok I see
and what now?
moon@antelope ~/code/tools [env]$ clojure/bin/clojure
Clojure 1.12.0
user=> but if I change dir
moon@antelope ~/code/test [env]$ ~/code/tools/clojure/bin/clojure
Error: Could not find or load main class clojure.main
Caused by: java.lang.ClassNotFoundException: clojure.mainyeah, that is probably because of the line 5 of the clojure script
which contains a relative path
when you install with prefix
you can change that to an absolute path of ~/code/tools/clojure/
Cool! it works now )
Thank you a lot for help!!
hey you are welcome. I'm not sure what is going on with the other installation method
I'm going to use clj tools form ./linux-install.sh
I've always installed from that linux-install.sh
now i can load without any issues )
[ring.adapter.jetty :refer [run-jetty]sorry for taking so much time
Huh, it seems that soon comes the time when one of the first questions asked in similar situations should be "are you using guix/nix?". :)
That S3Transporter warning generally indicates you're running tools.deps from a git dep or source, without the Java classes compiled -- which tracks with the weird "bunch of jars" in the script instead of the full uberjar of clojure-tools. I suspect this harks back to these *nix packager folks obsession with trying to build everything from source (and clearly getting something wrong here).