Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ANT: How to modify java.library.path in a buildfile

Tags:

java

ant

The java.library.path property appears to be read-only. For example when you run ant on the following buildfile

<project name="MyProject" default="showprops" basedir=".">
    <property name="java.library.path" value="test"/>
    <property name="some.other.property" value="test1"/>
    <target name="showprops">
        <echo>java.library.path=${java.library.path}</echo>
        <echo>some.other.property=${some.other.property}</echo>
    </target>
</project>

you get

> ant -version
Apache Ant version 1.6.5 compiled on June 2 2005

> ant -Djava.library.path=commandlinedefinedpath
Buildfile: build.xml
showprops:
    [echo] java.library.path=commandlinedefinedpath
    [echo] some.other.property=test1
BUILD SUCCESSFUL
Total time: 0 seconds

The output indicates that the java.library.path hasn't been changed, but some.other.property was set correctly.

I would like to know how to modify the java.library.path within a buildfile. Specifying the java.library.path on the ant command line is not really an easy option, because the library path location is not know at that time.

Note: I would like this to work so that I can specify the location of native libraries used in a unit test.

like image 987
Ivo Bosticky Avatar asked Jan 08 '09 01:01

Ivo Bosticky


2 Answers

Ant properties do not work the way you expect: they are immutable, i.e. you cannot change a property's value after you have set it once. If you run

ant -Dsome.other.property=commandlinedefinedpath

the output will no longer show

[echo] some.other.property=test1

like image 87
Peter Hilton Avatar answered Sep 22 '22 10:09

Peter Hilton


I think you can modify it if you use fork=true in your "java" task. You can supply java.library.path as a nested sysproperty tag.

like image 40
Yoni Roit Avatar answered Sep 21 '22 10:09

Yoni Roit