开发者

How can i edit path of a jar in ant

开发者 https://www.devze.com 2023-03-01 00:47 出处:网络
I would like to replace path of an existing jar based on OS . some thing like below: in windows : C:/apps/workspace/libs/rpm.jar

I would like to replace path of an existing jar based on OS .

some thing like below:

in windows : C:/apps/workspace/libs/rpm.jar

in unix : /user-id/projectname/libs/rpm.jar

Is there a way to remove C:/apps/workspace/libs from C:/apps/workspace/libs/rpm.jar .

editing my Question to :

Thanks Liv, But i have lot of libraries like this. right now i am maintaning a text file called "build.start.properties" with all libraries some ting like this

/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

And loading them to classptah using below target

    <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>

from the above target build.classpath.id looks like /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

When i work on unix I have to pic only jar n开发者_Go百科ames from file "build.start.properties" and update path like this

/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


Always use relative paths, that way you wont' be relying on library being at given location and on underlying OS.

Although this does not answer what you exactly asked for, but the suggestion will help you in the long run. Also, if possible, use Ivy + Ant (or Maven) to manage dependency.


you can use the ant task -- the folliwng is taken from the documentation (http://ant.apache.org/manual/Tasks/condition.html):

<condition property="isMacOsButNotMacOsX">
    <and>
      <os family="mac"/>

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

      </not>
    </and>
</condition>
0

精彩评论

暂无评论...
验证码 换一张
取 消