Ant:将路径转换为单独的属性

发布于 2024-12-06 03:09:13 字数 388 浏览 1 评论 0原文

我有一个包含几个 jar 文件的文件夹,这些文件都应该转到类路径:

<path id="my.classpath">
    <fileset dir="/tmp/mylibs" includes="*.jar" />
</path>

现在我希望能够将所有这些 jar 文件作为单独的属性引用, 例如,如果我有两个 jar 文件 foo.jar 和 bar.jar 那么我希望能够像

${foo.jar} (== /tmp/mylibs/foo.jar) 
${bar.jar} (== /tmp/mylibs/bar.jar)

在 Ant 中那样引用它们吗?

谢谢,彼得

I have a folder containing several jar files which should all go to a classpath:

<path id="my.classpath">
    <fileset dir="/tmp/mylibs" includes="*.jar" />
</path>

Now I would like to be able to reference all these jar files as a seperate property,
e.g. if I have two jar files foo.jar and bar.jar then I would like to be able to reference them like

${foo.jar} (== /tmp/mylibs/foo.jar) 
${bar.jar} (== /tmp/mylibs/bar.jar)

Is that somehow possible in Ant?

Thanks, Peter

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

瑕疵 2024-12-13 03:09:13

ant-contrib 的帮助下,您可以尝试以下操作:

<target name="test">
    <ac:for param="file">
        <fileset dir="/tmp/mylibs" includes="*.jar"/>
        <sequential>
                <antcall target="setImpl">
                    <param name="file" value="@{file}"/>
                </antcall>
                <echo>param: @{file}</echo>
        </sequential>
    </ac:for>
</target>

<target name="setImpl">
    <property name="filename" value="${file}" />
    <echo>property: ${filename}</echo>
</target>

对于覆盖属性值(如果需要)您还可以使用 ant-contrib

With help of ant-contrib you can try this:

<target name="test">
    <ac:for param="file">
        <fileset dir="/tmp/mylibs" includes="*.jar"/>
        <sequential>
                <antcall target="setImpl">
                    <param name="file" value="@{file}"/>
                </antcall>
                <echo>param: @{file}</echo>
        </sequential>
    </ac:for>
</target>

<target name="setImpl">
    <property name="filename" value="${file}" />
    <echo>property: ${filename}</echo>
</target>

For overriding property value (if you need) purpose you can also use ant-contrib

酒儿 2024-12-13 03:09:13

Ivy 有一个 artifactproperty 任务,旨在执行此操作为你。

该解决方案的唯一问题是它假设您使用 ivy 来解决依赖关系并管理类路径。

Ivy has a artifactproperty task which is designed to do this for you.

The only catch to this solution is that it assumes you're using ivy to resolve your dependencies and manage your classpath.

第七度阳光i 2024-12-13 03:09:13

将整个类路径放入单个属性的简单方法:

<path id="my.classpath">
    <fileset dir="/tmp/mylibs" includes="*.jar" />
</path>

<property name="classpath.property" refid="my.classpath"/>

<echo message="Classpath = "${classpath.property}""/>

我相信这将在 Eclipse .classpath 文件中工作。现在我面前没有人。如果您必须操作它,您可以通过过滤器链的 任务来完成。

An easy way to get the entire classpath into a single property:

<path id="my.classpath">
    <fileset dir="/tmp/mylibs" includes="*.jar" />
</path>

<property name="classpath.property" refid="my.classpath"/>

<echo message="Classpath = "${classpath.property}""/>

I believe this will work in an Eclipse .classpath file. I don't have one in front of me right now. If you have to manipulate it, you can do that via the <concat> task with the filterchains.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文