如何将命令行参数传递给 Play 1.x?

huangapple go评论50阅读模式
英文:

Ho to pass command line arguments to Play 1.x?

问题

如何在启动 Play 1.x 时传递命令行参数?
我找到了一个示例,用于选择 HTTP 端口或框架 ID,但没有用于自定义参数的示例。

英文:

How do I pass command-line arguments when starting Play 1.x?
I've found an example for selecting an HTTP port or a framework ID, but not for a custom argument.

答案1

得分: 0

将参数传递给 Play 1.x 是不可行的。
相反,您应该使用 JVM 自定义参数,使用属性之前的 -D 注解:

play run -Dbla_bla_enabled=true

在您的 Java 代码中,将其视为字符串值:

if(System.getProperty("bla_bla_enabled").equals("true")){
   ...
}

哦,还要记得检查是否为 null,如果该属性可能不存在。

英文:

Passing arguments to Play 1.x is not possible.
You should use JVM custom arguments instead, with a -D annotation before the property:

play run -Dbla_bla_enabled=true

In your Java code, treat it as a string value:

if(System.getProperty("bla_bla_enabled").equals("true")){
   ...
}

Oh, and remember to check for null if the property might be absent.

huangapple
  • 本文由 发表于 2020年1月6日 15:17:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/59608083.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定