This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-06-19
Channels
- # aws-lambda (1)
- # beginners (35)
- # cider (7)
- # cljsjs (2)
- # clojure (48)
- # clojure-austria (1)
- # clojure-conj (9)
- # clojure-dev (8)
- # clojure-india (6)
- # clojure-italy (12)
- # clojure-nl (8)
- # clojure-norway (3)
- # clojure-spec (9)
- # clojure-uk (92)
- # clojurescript (103)
- # community-development (7)
- # cursive (15)
- # datomic (75)
- # devcards (3)
- # emacs (3)
- # events (1)
- # fulcro (129)
- # hoplon (4)
- # immutant (2)
- # jobs (10)
- # leiningen (9)
- # off-topic (4)
- # onyx (2)
- # re-frame (45)
- # reagent (39)
- # reitit (40)
- # remote-jobs (4)
- # ring (2)
- # ring-swagger (9)
- # shadow-cljs (17)
- # tools-deps (31)
I had a really weird dream last night... a non-java programmer friend was somehow convinced they needed to install Kafka and run it.... and they weren't looking forward to that. And in my dream I tried to convince them to use an Isomorphic programming language. I am not even sure that actually makes any sense :thinking_face:
The only surprising thing about that dream is that you managed to convince them! Iāve never managed to convince anyone to use something like Clojure!
Bore da
(defn list*
"Creates a new seq containing the items prepended to the rest, the
last of which will be treated as a sequence."
{:added "1.0"
:static true}
([args] (seq args))
([a args] (cons a args))
([a b args] (cons a (cons b args)))
([a b c args] (cons a (cons b (cons c args))))
([a b c d & more]
(cons a (cons b (cons c (cons d (spread more)))))))
What does :static true do?see... I was at least correct on one thing... (that someone else can give a better explanation š )
knowing the limits of oneās own knowledge is possibly the most important thing you can know
Morning All... Sorry to ask the same question again, but I could really do with finding out the answer... Does anyone remember how much Conj tickets were in 2017, Early Bird and / or Standard Price..? I am trying to firm up support for me to attend this year, now that the dates are known...
@maleghast iāve done a bit of googling i cant find a price anywhere, best to alex miller i reckon
Thanks @guy - I Googled about a fair bit as well, I was hoping to happen on someone who remembered what they paid š
Okie dokie - I will have to just @ him on Twitter or something; I don't know__ him...
Iāve moved ur question to #clojure-conj hopefully that was what you were looking for š @maleghast
@maleghast 500$ for a late registration (sept for oct)
:kanye:
Hello š , wondering if anyone can help? I have a question about how to run a script written in clojure on my server.
I have a webapp that Iāve packaged into an uberjar using lein. This is deployed on my server and is happily running with java -jar xxx-standalone.jar
. I have now written a script that I want to run on the server too. How would I go about getting this script included in the uberjar, and how do I run the script on the server?
@cfeckardt yeah, sorry this is a really newbie question. I think Iāve included it in the uberjar, but what java command do I run on the server to run the script. Eg. I run java -jar xxx-standalone.jar
to run the webapp, what do I run to call the script that is contained within the uberjar?
are you trying to start a new JVM process on your server, or do you want your currently running server to execute some code?
if you want a new Java process then this might be helpful: https://clojure.org/reference/repl_and_main#_launching_a_script
if you want it in the same process then you probably want to be running an HTTP server and respond to some HTTP request?
I donāt want to run it in the same process - not trying to expose it via HTTP or anything. Itās just a one off script that I want to run on the server.
I took a look at this: https://clojure.org/reference/repl_and_main#_launching_a_script, but the script uses dependencies. The dependencies are all included in the uberjar (as is the script). Is there a way of calling the uberjar and telling it to run the script contained within in, eg. java -jar xxx-standalone.jar -run-this-script
The link says to run the script with java -cp clojure.jar clojure.main /path/to/myscript.clj arg1 arg2 arg3
but I donāt have the clojure.jar on the server, or the myscript.clj. All I have is the uberjar (which should hopefully contain the myscript.clj)
@jamescroft sounds like it would be simpler to make two different uberjars, one for the webapp and one for your script.
@thomas ok thanks. Still finding my feet with this stuff. Iād considered that option but it seemed like overkill and I wondered if there was a better way. Thanks
would java -cp xxx-standalone.jar clojure.main /path/to/myscript.clj
do it? i'm fuzzy on how uberjars work
(and if it's not in there it could be that you are missing (:gen-class)
in your (ns
at the top of your script
ok, thanks for the pointers
I would have thought you wouldnāt need to compile the script to java class files if youāre running it via the clojure.main
entry point.
There are certainly more options in this area now due to the ātools.depsā work that is ongoing.
options for eg. standalone scripts with dependencies
I donāt know about uberjars, but I assume they are like normal jars - ājava -jar foo.jarā loads foo into the classpath, then uses a default Main class (from distant memory) that is in the foo.jar metadata.
So you should be able to somehow specify a different entry point - youād need to :gen-class
to make it exposed as a class. Hmm.
if I unzip an uberjar I can see the file META-INF/MANIFEST.MF
containing:
Manifest-Version: 1.0
Built-By: korny
Created-By: Leiningen 2.5.3
Build-Jdk: 1.8.0_162
Main-Class: cloc2flare.cli
According to https://stackoverflow.com/questions/5474666/how-to-run-a-class-from-jar-which-is-not-the-main-class-in-its-manifest-file you can run any class with a public final static main
method
So I strongly suspect if you make a new namespace with a :gen-class
in the ns
header, and a -main
method, you can then run it from the uberjar just fine.
Something like:
(ns mypackage.cli
(:require
[stuff])
(:gen-class))
(defn -main [& args]
(puts "Hello world!"))
then java -cp MyUberjar.jar mypackage.cli
should load clojure (as itās in the uberjar) and run your -main
You can do it without :gen-class
and AOT: run the clojure.main
class and then specify the namespace whose -main
you want to run: java -cp foo.jar clojure.main -m my.namespace
(we actually run all our code that way and we don't AOT anything and we don't use :gen-class
)
We commonly have multiple namespaces containing -main
functions in a single JAR.
Please tell us more about this..
@U7ANZ2MTK So many problems... unfortunately, since the default Leiningen templates include AOT and :gen-class
, and that's perpetuated in most of the tutorials and books, it tends to be the way most beginners get started -- and then continue with until they start tripping over problems. Stale class files, incompatible versions of a class being loaded, transitive compilation (so the whole world ends up getting compiled), weird breakages in REPL-based workflows, incompatibilities with the maven-shade-plugin, conflict between "source" and "binary" artifacts (e.g., Cursive issue 234), confusion over differences between e.g., lein run
behavior and running the result of lein uberjar
when not all of the fiddly bits line up, etc.
AOT is sort of OK as a way to minimize start up time if you really need to do that for a complete application just at the very last step when building an uberjar for deployment.
@U04V70XH6 thanks a lot!
that's really helpful
:gen-class
is sort of OK if you absolutely must generate a Java-compatible .class
file for Java-calling-Clojure scenarios where you want the Clojure namespace to look exactly like a Java class (e.g., providing a library that can be used directly from a Java application -- and you don't want the Java code to have to use the Clojure Java API).
Personally, I think the Clojure Java API is far and away the more powerful way to integrate Clojure into a Java application as it opens up the whole of Clojure, dynamically. That's how we use it at work, from our legacy apps.
BTW, that also means you can start a REPL with all your code/dependencies available using an uberjar: java -cp foo.jar clojure.main
-- with no -m
argument will start a REPL.
Oh, sorry, yes, -cp
.
Fixed!