Setting an environment variable from within the sbt shell(在 sbt shell 中设置环境变量)
问题描述
我希望能够在交互式 sbt shell 中设置一个环境变量,但我似乎找不到这样做的方法.(我查看了官方 sbt 文档以及 stackoverflow 均未成功).
I would like to be able to set an environment variable from within the interactive sbt shell, and I can't seem to find a way to do that. (I have looked on the official sbt docs as well as on stackoverflow without success).
我想明确一点,我不想必须在 build.sbt
文件中设置这个环境变量,而是能够改变它在我的交互式 sbt shell 会话中即时运行,以便环境变量用于我运行的下一个 sbt 命令.
I want to make it clear that I don't want to have to set this environment variable in the build.sbt
file, but rather be able to change it on the fly on my interactive sbt shell session, so that the environment variable is used for the next sbt commands I run.
例如,我希望能够(从 sbt shell 中)执行以下操作:
For example, I would like to be able to do something like (from within the sbt shell):
> set_environment_variable("foo", "foo_value")
> `mymodule`/run
> (... program runs and completes)
> set_environment_variable("foo", "another_foo_value")
> `mymodule`/run
这可能吗?如果是,我该怎么做?
Is this possible? And if it is, how can I do it?
推荐答案
使用 sbt 0.13.15
我发现唯一对我有用的是使用 eval代码>.
Using sbt 0.13.15
the only thing I've found which has worked for me is to use eval
.
> eval System.setProperty("foo", "foo_value")
> `mymodule`/run
> ...
> eval System.setProperty("foo", "another_foo_value")
> `mymodule`/run
这篇关于在 sbt shell 中设置环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 sbt shell 中设置环境变量
基础教程推荐
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- 在螺旋中写一个字符串 2022-01-01