2011-04-26 33 views
0

我想基於操作系統取代現有罐子的路徑。我怎樣才能編輯一個罐子在螞蟻的路徑

一些東西象下面這樣:
在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

和裝載他們用低於目標

<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 classptah看起來像 /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上工作,我不得不從PIC文件「build.start.properties」只罐子名和更新路徑這樣

/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。罐子:/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

回答

0

始終使用相對路徑,這種方式你不會'依靠圖書館在特定位置和底層操作系統。

雖然這並不能回答你確切要求的內容,但從長遠來看,這個建議對你有幫助。另外,如果可能,請使用Ivy + Ant(或Maven)來管理依賴關係。

0

你可以使用ant任務 - folliwng從文件(http://ant.apache.org/manual/Tasks/condition.html)採取:

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

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

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

感謝麗芙,但我有很多像這樣的庫。現在我正在用所有類似於這個 – Jagan 2011-04-26 16:49:22

+0

的庫來保存文本文件,您仍然可以執行此操作,並設置存儲基本路徑的環境變量。只需將這個變量的路徑(我們稱之爲lib_path)初始化到windows路徑:然後使用來檢查它是否是unix或如果是,則將值設置爲unix路徑: ...然後使用該變量引用lib $ {lib_path}/rpm.jar - 它有道理嗎? – Liv 2011-04-26 16:53:18