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 中设置环境变量


基础教程推荐
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 如何对 Java Hashmap 中的值求和 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01