简体   繁体   English

如何在Ant中添加与java -D等效的系统属性

[英]How to add system property equivalent to java -D in Ant

I need to set java -Djava.library.path=/some/path and 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 我用Google搜索和找到的唯一东西就是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中部署这个耳朵。

Here is an example Ant target run that executes the example.jar and 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>

你试过跑吗?

ant -Djava.library.path=/some/path ...  ?

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在Application Server(Web Server)中创建和部署我们的应用程序,在我们的JBoss案例中,我们必须修改

run.sh
and add the java.library.path as a VM argument there. 并在那里添加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参数是不正确的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM