简体   繁体   中英

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.

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

 <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.

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" :

<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

run.sh
and add the java.library.path as a VM argument there.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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