在不同操作系统上工作时更新jar的相对路径

时间:2011-04-26 17:23:01

标签: ant

我想基于操作系统替换现有jar的路径。 现在我正在维护一个名为“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

    <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-数学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。罐子:/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-MAT​​H- 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-共享记录-service-0.3.jar

1 个答案:

答案 0 :(得分:0)

使用条件

<condition property="isWindows">
<os family="windows" />
</condition>
<condition property="isUnix">
    <os family="unix" />
</condition>

On the targets then u can use

<target name="path_if_unix" if="isUnix">
    <map from="C:" to="${unix.xenv}" />
    <map from="" to="${unix.xenv}" />
</target>