How can I specify JVM flags so that they apply only to one alias in a project.clj
file?
Specifically I want to try the built in server capability in Clojure 1.8.0.
I can do this with an uberjar and the command:
java -Dclojure.server.interactive="{:port 8411 :accept srv.action/process}" -jar target\uberjar\srv-0.1.0-SNAPSHOT-standalone.jar
But I was hoping I could set that -D...
from within a lein alias.
I tried this
:aliases {
"serve" [:jvm-opts ["-Dclojure.server.interactive={:port 8411 :accept srv.action/process}"] "run"]
}
But I get
java.lang.ClassCastException: clojure.lang.Keyword cannot be cast to java.lang.String
Is it possible to do this? I am using "Leiningen 2.6.1 on Java 1.8.0_92 Java HotSpot(TM) 64-Bit Server VM"
Leiningen profiles are definitely the way to do this. You can define a profile with any of the usual options, in your case :jvm-opts
. In your profile.clj include something similar to the following:
:profiles {:clj-server {:jvm-opts ["-Dclojure.server.interactive={:port 8411 :accept srv.action/process}"]}}
Then you can tell leiningen you wish to use this profile via with-profile.
lein with-profile clj-server run
However, this will only use the options specified in the new profile. If you wish to activate the new profile in addition to the default profiles (dev, test, etc) you need to prepend the profile with a +
.
lein with-profile +clj-server run
If you're lazy, like me, you can define an alias to run different tasks utilizing this newly defined profile:
:aliases {"clj-server-run" ["with-profile" "+clj-server" "run"]}
Then it's as easy as calling lein clj-server-run
.
Hopefully this helps. I truly recommend reading through the leiningen documentation provided as well as its extremely useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With