Geo Geo - 7 months ago 54
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


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

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

    <propertyref prefix="test."/> 

You can reference external system properties:

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

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:

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

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.


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

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

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

will not work, but the following should:

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

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