tags:

views:

890

answers:

2

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

java -Djava.library.path=somedir Whatever
+1  A: 

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

VonC
It doesn't work.
Geo
I left work. I'll try it tomorrow and if it works I'll mark your answer. Thanks!
Geo
A: 

I've managed to get it to work using the environment variable ANT_OPTS. I would like to see this done from a task if it's possible.

Geo
I was missing the specific property you were trying to pass: I have updated my answer.
VonC