如何从 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>
和
应该是你要找的
<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任务中使用它们:这个propertyset
可以按需使用;当向下传递到一个新进程时,所有当前匹配给定前缀的 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
属性的事实!
如本主题所述:
如果您尝试在 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屋!