3

if I use lein run the project is no problem.

But when I use jave -jar blog.jar after lein uberjar It happen exceptions.

16-Jul-20 11:28:05 DESKTOP-C3SC9AR INFO [slf4j-timbre.adapter] - >> starting..  *db*
Exception in thread "main" java.lang.RuntimeException: could not start [*db*] due to

        .....

Caused by: java.lang.Exception: :jdbc-url, :datasource, or :datasource-

AND my project.clj file

(defproject blog "0.1.0-SNAPSHOT"

  :description "FIXME: write description"
  :url "http://example.com/FIXME"

  :dependencies ....

  :min-lein-version "2.0.0"
  :uberjar-name "blog.jar"
  :jvm-opts ["-server"]

  :main blog.core
  :migratus {:store :database}

  :plugins [[lein-environ "1.0.1"]
            [migratus-lein "0.2.0"]]

  :profiles
  {:uberjar {:omit-source true
             :env {:production true}
             :aot :all
             :source-paths ["env/prod/clj"]}
   :dev           [:project/dev :profiles/dev]
   :test          [:project/test :profiles/test]
   :project/dev  ...
   :project/test ...
   :profiles/dev  {:env {:database-url "jdbc:postgresql://localhost/blog?user=postgres&password=root"}}
   :profiles/test {}})

Maybe it can't find the key of "database-url"?

Tornado
  • 115
  • 1
  • 7

1 Answers1

3

Data provided via environment settings in project.clj are not provided when you use java directly. It's your responsibility to make sure the environment settings visible to the app provide any credentials or connection info needed.

It could look something like:

DATABASE_URL="jdbc...." java -jar my-project-standalone.jar
noisesmith
  • 20,076
  • 2
  • 41
  • 49
  • oh,I see.But any other convenient method to set environment or start jar?Thanks. – Tornado Jul 20 '16 at 06:02
  • @Tornado You could wrap it in a unix-shell script or windows bat file to hide the "complexity" from the user – murphy Jul 20 '16 at 07:14
  • @ChrisDevo environ is the tool that lets you load things easily from the environment as set in project.clj, but it can't set vars when you aren't running lein - the intended usage of environ is that your deploy target sets the environment variables – noisesmith Jul 21 '16 at 01:56
  • @noisesmith `environ` will load environment variables from several sources, not just `project.clj`: https://github.com/weavejester/environ/blob/master/environ/src/environ/core.clj#L39 – ChrisDevo Jul 21 '16 at 17:49
  • @ChrisDevo right, and one of those is environment variables as shown in my answer - I assumed based on the environment being set in the project.clj that environ was already used – noisesmith Jul 22 '16 at 03:44
  • @noisesmith "but it can't set vars when you aren't running lein" Could you please show me where `environ` requires Leiningen? – ChrisDevo Jul 22 '16 at 19:22
  • it doesn't set vars, it gets them from the environment (or system properties). It's an aid to parsing values from the env, not a way to set them as is being requested here. – noisesmith Jul 23 '16 at 00:04
  • @noisesmith Those are your words, not mine. You're focusing on the wrong point and avoiding a direct question. – ChrisDevo Jul 25 '16 at 17:18