有没有办法在leinegen中设置系统属性? [英] Is there a way to set system properties in leinegen?

查看:130
本文介绍了有没有办法在leinegen中设置系统属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

开始使用默认情况下使用 :test 个人资料运行的lein任务(实际 测试 )。我想做的是从等效的

Starting a lein task (actually test, which runs by default with the :test profile). What I'd like to do is start with the equivalent of


java -Dproperty1 = value -Dproperty2 = value2 task

java -Dproperty1=value -Dproperty2=value2 task

在网上有一些参考,建议这应该像这样工作:

There are some references on the web that suggest that this should work fine like this:

project.clj:

project.clj:

...
:profiles {:test {:jvm-opts ["-Dproperty1=value" "-Dproperty2-value"]}}

配置文件是正确的,如果我插入一些实际的jvm参数(例如像-XX:+ PrintGC)它工作正常。但似乎没有拿起系统属性。是否有正确的方法?

This is ignored in my test runner. The profile is correct, If I insert some actual jvm args (e.g something like "-XX:+PrintGC") it works fine. But doesn't seem to pick up the system properties. Is there a correct way to do this?

推荐答案

我们使用环境

安装插件后,您只需在项目中创建一个文件 .lein-env 包含要设置的环境变量的映射的根,例如:

Once you install the plugin, all you need to do is create a file .lein-env in your project root containing a map of environment variables to be set, such as:

{
  :s3-access-key     "some key"
  :s3-secret-key     "some secret"
}

然后,在您的代码中,您可以使用:

Then, in your code, you can use:

(require '[environ.core :refer [env]])
(env :s3-access-key) ;; "some key"

这让我指向测试中的stub服务器,如果没有提供 .lein-env ,生产环境将使用系统环境变量。

This lets me point to, say, stub server in test but the real thing in production as environ will use the system environment variables if no .lein-env is provided.

这篇关于有没有办法在leinegen中设置系统属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆