tools.build does not natively support WARs, is that right? If I want to deploy a Clojure web app that does not embed a server, is there a way to package a JAR to do this? I've been looking at Jetty documentation and it seems like I need a ServletContext in which I expose my Ring handlers (which are servlets if I am not mistaken). Provided I have this (and anything else I may need), is there a way to get this job done? Possibly through some combination of tools.build and Maven directly?
I never came around to build anything, Turned out I did not really need to for the task I had at hand 🤷
correct, there are no provided tasks for wars. I'm in no way opposed to that, just wasn't something I wanted to take on at the time. Would be open to additions or seeing external libs to do so. it's possible you could get somewhere with a combination of pom gen and shelling out to a mvn process
cool, I'll see what I can figure out. The salient difference seems to be between the WEB-INF and META-INF directories that get outputted, though I imagine that that is not as simple as a name change. Guess I'll find out 🤷🏻♂️ thanks!
there is an ask question for this and a corresponding jira btw https://ask.clojure.org/index.php/11341/possible-build-uberwar-using-deps-using-tools-build-other-tool?show=11343#a11343 - happy to have votes or info on those
mechanically, war files are just jar files with stuff in special places, and tools.build supports both copying stuff into an assembly directory and jar'ing from there, so you have much of the tools you need. assembling the jar files is probably the least obvious part of that, but the basis contains a :libs map that includes the path to jar files, so it is not a big leap to iterate over that map and copy the jar files to a place.
I have this code in user.clj.
(def xyz (fn-might-throw-error))
I b/compile it and the fn throws an error and the compile fails.
Does it mean the compile process actually runs the code during compilation and why?
If user.clj is on the classpath, Clojure automatically loads (and compiles and runs) it.
You should not have user.clj on your regular classpath -- you should put it in something like a dev/ folder and have a :dev alias with :extra-paths ["dev"] so it is only added when you are doing development.
i pick the wrong name here.
(I personally think the auto-loading of user.clj was a bad idea but it got added to Clojure a very long time ago)
it's a source file deep under src/
Oh, OK. So not literally (ns user ..)
Right...
Well, top-level def forms are evaluated whenever a ns is loaded.
And compilation loads nses.
A top-level def form should never cause side-effects (e.g,. throw exceptions).
A quick workaround would be to do (def xyz (delay (fn-might-throw-error))) and then @xyz instead of plain xyz wherever you use it.
But it would be better to just not have top-level def forms that aren't simple constant expressions.
ok that makes senses. thanks.