有没有办法在 leinegen 中设置系统属性? [英] Is there a way to set system properties in leinegen?
问题描述
启动 lein 任务(实际上是 test,默认情况下使用 :test 配置文件运行).我想做的是从相当于
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 任务
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?
推荐答案
找到了一个答案,供其他有此问题的人使用:
Found an answer, for anyone else who's struggling with this:
由于我需要在开始该过程之前注入环境属性,因此我执行了以下操作:
Since I needed to inject environment properties before I started the process, I did the following:
将 shell 插件添加到您的 project.clj:
add the shell plugin to your project.clj:
:plugins [[ lein-shell "0.4.1"]]
:plugins [[ lein-shell "0.4.1"]]
然后将准备任务添加到您的个人资料中.但是有一个问题 - 你认为你可以这样做:
and then add a prep task to your profile. But there's a wrinkle - you'd think you could do this:
:profiles {:test {:prep-tasks [["shell" "export" "foo=bar"]]}}
但这不起作用,因为 shell 没有看到导出命令 - 你得到没有这样的文件",因为它是 bash 的一部分,并且没有名为导出"的可执行文件.所以我创建了一个名为setenv.sh"的脚本并从 shell 运行它:
But this doesn't work, as shell doesn't see the export command - you get "no such file", since it's part of bash and there's no executable file called "export". So I created a script called "setenv.sh" and ran that from shell:
:profiles {:test {:prep-tasks [["shell" "./test/setenv.sh"]]}}
实际上这不起作用,变量不会转移到子流程.把它留在这里是因为它可能对某人有用.
actually this does not work, the variables are not carried over to the subprocess. Left it here because it might be useful to someone as is.
实际上必须创建一个调用 export 然后运行 lein 的 shell 脚本.绝对不是最优雅的解决方案.
actually had to create a shell script that calls export and then runs lein. Definitely not the most elegant solution.
这篇关于有没有办法在 leinegen 中设置系统属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!