如何从Java任务设置Java库路径? [英] How do I set the Java library path from a Java task?
问题描述
是否可以在java任务中指定库路径?类似于:
Is it possible to specify a library path in a java task? Like the equivalent of:
java -Djava.library.path=somedir Whatever
推荐答案
< propertyset> ;
和< syspropertyset>
应该是你要找的东西
<propertyset>
and <syspropertyset>
should be what you are looking for
另见此主题。
您可以在java ant任务中逐个设置它们:
You can set them one by one within your java ant task:
<sysproperty key="test.classes.dir"
value="${build.classes.dir}"/>
乏味......或者你可以将它们作为一组Ant属性传递下去:
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>
然后在你的java ant任务中使用它们:这个属性集
可以按需使用;传递给新进程时,传递与给定前缀匹配的所有当前ant属性:
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>
我完全错过了你试图通过的事实 java.library.path
property!
如此主题:
I completely missed the fact you were trying to pass java.library.path
property!
As mentioned in this thread:
如果您尝试设置它在java任务之外的值,Ant忽略它。所以我把除了那个之外的所有属性放在我的syspropertyset中,它按预期工作。
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"/>
</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>
(尽管您可以尝试使用 fork
如果不起作用,属性设置为true
(注意:你无法修改其值)
(although you might try that with the "fork
" attribute set to true if it does not work)
(Note: you cannot modify its value though)
这篇关于如何从Java任务设置Java库路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!