首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在ant中编辑jar的路径

如何在ant中编辑jar的路径
EN

Stack Overflow用户
提问于 2011-04-27 00:26:23
回答 2查看 182关注 0票数 0

我想替换基于操作系统的现有jar的路径。

下面是一些类似的东西:

在windows中: C:/apps/workspace/libs/rpm.jar

在unix中: /user-id/projectname/libs/rpm.jar

有没有办法从C:/apps/workspace/libs/rpm.jar中删除C:/apps/workspace/libs。

将我的问题编辑为:

谢谢Liv,但我有很多这样的库。现在,我正在维护一个名为"build.start.properties“的文本文件,所有的库都是这样的

/gwt/X/2.1.0/gwt-servlet.jar

/gwt/X/2.1.0/gwt-user.jar /gwt/X/2.1.0/gwt-dev.jar

/gwt/X/2.1.0/gwt-soyc-vis.jar /log4j/X/1.2.15/log4j-1.2.15.jar /GWT_LOG/X/3.0.3/gwt-log-3.0.3.jar /GWT_math/X/2.1/GWT-math 2.1.jar/GWT_math/X/2.1/GWT-math server-2.1.jar /GWT_Commons_Logging/X/0.3/GWT-commons-logging/gwt-commons-logging-0.3.jar

/GWT_Commons_Logging/X/0.3/GWT-commons-logging/gwt-commons-logging-service-0.3.jar

并使用以下目标将它们加载到classptah

代码语言:javascript
复制
    <loadfile property="jars.list.property" srcfile="mybuild/build.start.properties">
        <filterchain>
            <expandproperties />
            <striplinecomments>
                <comment value="#" />
            </striplinecomments>
            <tokenfilter>
                <ignoreblank />
            </tokenfilter>
            <prefixlines prefix="," />
            <striplinebreaks />
        </filterchain>
    </loadfile>
    <filelist id="build.libs" dir="" files="${jars.list.property}" />

    <pathconvert targetos="unix" property="build_unix.libs" refid="build.libs">

        <map from="C:" to="${unix.xenv}" />
        <map from="" to="${unix.xenv}" />
    </pathconvert>
    <pathconvert targetos="windows" property="build_windows.libs" refid="build.libs">
        <map from="C:" to="${windows.xenv}" />
        <map from="" to="${windows.xenv}" />
    </pathconvert>
    <path id="build.classpath.id">
        <pathelement path="${build_windows.libs}" />
        <pathelement path="${build_unix.libs}" />
    </path>
    <echo message="Build Libraries classpath: ${toString:build.classpath.id}" />
</target>

从上面的目标看,build.classpath.id看起来像/gwt/X/2.1.0/gwt-servlet.jar:/gwt/X/2.1.0/gwt-user.jar:/gwt/X/2.1.0/gwt-dev.jar:/gwt/X/2.1.0/gwt-soyc-vis.jar:/log4j/X/1.2.15/log4j-1.2.15.jar:/GWT_LOG/X/3.0.3/gwt-log-3.0.3.jar:GWT_MATH/X/2.1/gwt-math-2.1.jar:/GWT_MATH/X/2.1/gwt-math-server-2.1.jar:/GWT_Commons_Logging/X/0.3/GWT-commons-logging/gwt-commons-logging-0.3.jar:/GWT_Commons_Logging/X/0.3/GWT-commons-logging/gwt-commons-logging-service-0.3.jar

当我在unix上工作时,我只需要从文件"build.start.properties“中提取jar名称,并像这样更新路径。

/WebContent/WEB_INF/lib/gwt-servlet.jar:/WebContent/WEB_INF/lib/gwt-user.jar:/WebContent/WEB_INF/lib/gwt-dev.jar:/WebContent/WEB_INF/lib/gwt-soyc-vis.jar:/WebContent/WEB_INF/lib/log4j-1.2.15.jar:/WebContent/WEB_INF/lib/gwt-log-3.0.3.jar:/WebContent/WEB_INF/lib/gwt-math-2.1.jar:/WebContent/WEB_INF/lib/gwt-math-server-2.1.jar:/WebContent/WEB_INF/lib/gwt-commons-logging-0.3.jar:/WebContent/WEB_INF/lib/gwt-commons-logging-service-0.3.jar

EN

回答 2

Stack Overflow用户

发布于 2011-04-27 00:29:53

总是使用相对路径,这样你就不会依赖于给定位置的库和底层操作系统。

虽然这并没有完全满足你的要求,但从长远来看,这个建议会对你有所帮助。此外,如果可能,请使用Ivy + Ant (或Maven)来管理依赖项。

票数 0
EN

Stack Overflow用户

发布于 2011-04-27 00:31:20

您可以使用ant任务--下面的内容取自文档(http://ant.apache.org/manual/Tasks/condition.html):

代码语言:javascript
复制
<condition property="isMacOsButNotMacOsX">
    <and>
      <os family="mac"/>

      <not>
        <os family="unix"/>

      </not>
    </and>
</condition>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5793332

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档