Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在ant中编辑jar的路径_Ant - Fatal编程技术网

如何在ant中编辑jar的路径

如何在ant中编辑jar的路径,ant,Ant,我想替换基于OS的现有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 将我的问题编辑为: 谢谢丽芙,但我有很多这样的图书馆。现在,我正在维护一个名为build.start.properties的文本文件,其中包含一些类似这样的库

我想替换基于OS的现有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

将我的问题编辑为:


谢谢丽芙,但我有很多这样的图书馆。现在,我正在维护一个名为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看起来像 /1.1.1.0/gwt/2.1/2.1.0/2.1/2.1/2.1.0/gwt-1.1.0/gwt-1.1.0/gwt-dev-1.1.1/2.1/2.1/2.1/2.0/gwt/2.1/2.1/gwt/2.1/2.1/2.1/1/2.1/1/2.1/2.1/2.1/2.1/2.1/2.1/2.1/2.1/2.1/2.1.1.1.1.1.1.1.1.1/1/1/1/1/1/1/1/1/1/1/2.1.1.1.1.1.1.1.1.1.1.1.1/1/1/1/2.1.1.1/1/1/1.1/1/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-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/lib/gwt/lib/gwt-commons-logging-0.3.jar:/WebContent/WEB_-INF/lib/gwt-commons-logging-service-0.3.jar始终使用相对路径,这样您就不会依赖于位于给定位置的库和底层操作系统


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

您可以使用Ant任务-从文档中获取folliwnghttp://ant.apache.org/manual/Tasks/condition.html:

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

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

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

谢谢丽芙,但我有很多这样的图书馆。现在我正在维护一个包含所有库的文本文件,有些库是这样的,您仍然可以这样做,并设置一个存储基本路径的环境变量。只需初始化此变量的路径,我们将其称为windows路径的lib_path:然后使用来检查它是否为unix,并将值设置为unix路径(如果为):。。。然后使用该变量引用lib${lib_path}/rpm.jar——这有意义吗?