java 在启动时传递 jboss 参数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5512258/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 11:28:52  来源:igfitidea点击:

Passing jboss argument on startup

javajboss

提问by London

I'm trying to pass arguments to my jboss server on start up, its a string, but it always gets null when war is deployed here is how I do it:

我试图在启动时将参数传递给我的 jboss 服务器,它是一个字符串,但是当这里部署War时它总是为空,这是我的做法:

./run.sh -Dfile.config=/home/stats/config.xml -c default -b 192.168.1.102

Strange this is that I don't this property passed to VM when looking at log :

奇怪的是,在查看日志时,我没有将此属性传递给 VM:

[ServerInfo] VM arguments: -Dprogram.name=run.sh -Xms1303m -Xmx1303m -XX:MaxPermSize=256m -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Dsun.lang.ClassLoader.allowArraySyntax=true -Djava.net.preferIPv4Stack=true -Djava.endorsed.dirs=/apps/jboss/lib/endorsed

Can anyone figure out what I'm doing wrong? thank you

谁能弄清楚我做错了什么?谢谢

EDIT

编辑

This is how I reference this property in the code :

这就是我在代码中引用此属性的方式:

Properties property = System.getProperties();
String fileName = (String)property.get("file.config");

This works for me on windows, starting jboss from eclipse :

这在 Windows 上对我有用,从 eclipse 启动 jboss:

enter image description here

在此处输入图片说明

I'm trying to run this server from linux box this time.

这次我试图从 linux box 运行这个服务器。

采纳答案by London

I used environment variables. I set them before starting jboss, then collecting them inside my Class running on jboss.

我使用了环境变量。我在启动 jboss 之前设置它们,然后将它们收集到我在 jboss 上运行的类中。

回答by Heiko Rupp

You should put that into JAVA_OPTSenv variable:

您应该将其放入JAVA_OPTSenv 变量中:

$ export JAVA_OPTS="-Dfile.config=/home/stats/config.xml"
$ bin/run.sh

before starting JBoss or if this is not a one time option, put that in bin/run.confin the JAVA_OPTSexpression there

JBoss的开始之前,或者如果这不是一个时间选项,把在bin/run.confJAVA_OPTS表达中,