java 如何在Ant中添加相当于java -D的系统属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2378357/
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
How to add system property equivalent to java -D in Ant
提问by Shervin Asgari
I need to set java -Djava.library.path=/some/pathand I want to do it when I am running my ant script, building my jar.
我需要设置java -Djava.library.path=/some/path并且我想在运行我的 ant 脚本、构建我的 jar 时这样做。
I think I have to use
我想我必须使用
<sysproperty key="java.library.path" value="/some/path"/>
but it doesnt work. I cannot make the syntax work. The only thing I have Googled and found is sysproperty in conjunction with
但它不起作用。我无法使语法起作用。我在谷歌上搜索并发现的唯一一件事是 sysproperty 与
<java classname>
but that doesnt make any sense to me.
但这对我没有任何意义。
I am not sure if this is relevant, but I am using ant to create a ear and deploying this ear in JBoss.
我不确定这是否相关,但我正在使用 ant 创建一个耳朵并在 JBoss 中部署这个耳朵。
采纳答案by dokaspar
Here is an example Ant target runthat executes the example.jarand passes a system property with key="java.library.path"and value="/some/path":
下面是一个例子Ant目标run执行所述example.jar并传递系统属性key="java.library.path"和value="/some/path":
<target name="run">
<java jar="example.jar" fork="true">
<jvmarg value="-Djava.library.path=/some/path"/>
</java>
</target>
回答by Omry Yadan
did you try to run
你试过跑吗
ant -Djava.library.path=/some/path ... ?
回答by Shervin Asgari
I found out how I can solve this.
我发现了如何解决这个问题。
Seems like since we are using ant to create and deploy our application in a Application Server (Web Server), in our case JBoss, we had to modify
似乎因为我们使用 ant 在应用程序服务器(Web 服务器)中创建和部署我们的应用程序,在我们的例子中 JBoss,我们不得不修改
run.sh并在那里添加 java.library.path 作为 VM 参数。
Something like this:
像这样的东西:
JBOSS_NATIVE_DIR="$JBOSS_NATIVE_DIR:/usr/lib/ure/lib/"
JAVA_OPTS="$JAVA_OPTS -Djava.library.path=$JBOSS_NATIVE_DIR"
Thus, it is not correct to pass in VM arguments in ant.
因此,在 ant 中传入 VM 参数是不正确的。

