Geo Geo - 25 days ago 9
Java Question

How do I set the Java library path from a Java task?

Is it possible to specify a library path in a java task? Like the equivalent of:

java -Djava.library.path=somedir Whatever

Answer

<propertyset> and <syspropertyset> should be what you are looking for

See also this thread for instance.


You can set them one by one within your java ant task:

<sysproperty key="test.classes.dir" 
             value="${build.classes.dir}"/> 

tedious... or you can pass them down as a block of Ant properties:

<syspropertyset> 
    <propertyref prefix="test."/> 
</syspropertyset> 

You can reference external system properties:

<propertyset id="proxy.settings"> 
    <propertyref prefix="http."/> 
    <propertyref prefix="https."/> 
    <propertyref prefix="socks."/> 
</propertyset> 

and then use them within your java ant task: This propertyset can be used on demand; when passed down to a new process, all current ant properties that match the given prefixes are passed down:

<java>
     <!--copy all proxy settings from the running JVM--> 
     <syspropertyset refid="proxy.settings"/> 
     ...
</java>

I completely missed the fact you were trying to pass java.library.path property!
As mentioned in this thread:

if you try to set its value outside of the java task, Ant ignores it. So I put all properties except for that one in my syspropertyset and it works as expected.

meaning:

<property name="java.library.path" location="${dist}"/>

<propertyset id="java.props">
    <propertyref name="java.library.path"/>
</propertyset>

<target name="debug">
    <java>
        <syspropertyset refid="java.props"/>
    </java>
</target>

will not work, but the following should:

<target name="debug">
    <java>
        <sysproperty key="java.library.path" path="${dist}"/>
    </java>
</target>

(although you might try that with the "fork" attribute set to true if it does not work)
(Note: you cannot modify its value though)