ant腳本if
A. 命令行使用ant腳本編譯時出現OutOfMemoryError: GC overhead limit exceeded
根據sun的說法: "if too much time is being spent in garbage collection: if more than 98% of the total time is spent in garbage collection and less than 2% of the heap is recovered, an OutOfMemoryError will be thrown."
gc超過98%以上的時間去釋放小於2%的堆空間時會報這個錯誤
1、增加你那個XX參數
2、增加堆大小,-Xmx可以再增加,譬如2G內存增加到1300m
3、使用jstat監控gc,其vmid參數可用jps -lv查找
B. android如何使用ant批量打包
ps :後期熟悉ant的話,可以使用純ant腳本或者使用另一種更好的自動化打包工具(maven)關鍵代碼如下:package com.cn.ant; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import org.apache.tools.ant.DefaultLogger; import org.apache.tools.ant.Project; import org.apache.tools.ant.ProjectHelper; public class AntTest { private Project project; public void init(String _buildFile, String _baseDir) throws Exception { project = new Project(); project.init(); DefaultLogger consoleLogger = new DefaultLogger(); consoleLogger.setErrorPrintStream(System.err); consoleLogger.setOutputPrintStream(System.out); consoleLogger.setMessageOutputLevel(Project.MSG_INFO); project.addBuildListener(consoleLogger); // Set the base directory. If none is given, "." is used. if (_baseDir == null) _baseDir = new String("."); project.setBasedir(_baseDir); if (_buildFile == null) _buildFile = new String(projectBasePath + File.separator + "build.xml"); //ProjectHelper.getProjectHelper().parse(project, new File(_buildFile)); // 關鍵代碼 ProjectHelper.configureProject(project, new File(_buildFile)); } public void runTarget(String _target) throws Exception { // Test if the project exists if (project == null) throw new Exception( "No target can be launched because the project has not been initialized. Please call the 'init' method first !"); // If no target is specified, run the default one. if (_target == null) _target = project.getDefaultTarget(); // Run the target project.executeTarget(_target); } // private final static ArrayList<String> flagList = new ArrayList<String>(); //也可以使用集合,不過需要手動添加項 private final static String[] flagList = new String[]{"htc","moto","oppo"};//此處初始化市場標識 private final static String projectBasePath = ""; //項目的根目錄,需要配置 private final static String ApkPath = ""; //要改名後拷貝的目錄,需要配置 private final static String placeHolder = ""; //佔位符,需要配置 public static void main(String args[]) { //flagList.add("htc"); //flagList.add("moto"); //flagList.add("oppo"); try { System.out.println("---------ant批量自動化打包開始----------"); for(String flag : flagList){ //先修改manifest文件:讀取臨時文件中的@market@修改為市場標識,然後寫入manifest.xml中 String tempFilePath = projectBasePath + File.separator + "AndroidManifest.xml.temp"; String filePath = projectBasePath + File.separator + "AndroidManifest.xml"; write(filePath,read(tempFilePath, flag)); //執行打包命令 AntTest mytest = new AntTest(); mytest.init( projectBasePath + File.separator + "build.xml", projectBasePath); mytest.runTarget("clean"); mytest.runTarget("release"); //打完包後執行重命名加拷貝操作 //String flag = "htc"; File file = new File(projectBasePath + File.separator +"bin"+File.pathSeparator+"MainActivity-release.apk");//bin目錄下簽名的apk文件 file.renameTo(new File(ApkPath + File.separator + "MainActivity_"+flag+".apk")); } System.out.println("---------ant批量自動化打包結束----------"); } catch (Exception e) { e.printStackTrace(); System.out.println("---------ant批量自動化打包中發生異常----------"); } } public static String read(String filePath,String replaceStr) { BufferedReader br = null; String line = null; StringBuffer buf = new StringBuffer(); try { // 根據文件路徑創建緩沖輸入流 br = new BufferedReader(new FileReader(filePath)); // 循環讀取文件的每一行, 對需要修改的行進行修改, 放入緩沖對象中 while ((line = br.readLine()) != null) { // 此處根據實際需要修改某些行的內容 if (line.contains(placeHolder)) { line = line.replace(placeHolder, replaceStr); buf.append(line); } else { buf.append(line); } buf.append(System.getProperty("line.separator")); } } catch (Exception e) { e.printStackTrace(); } finally { // 關閉流 if (br != null) { try { br.close(); } catch (IOException e) { br = null; } } } return buf.toString(); } /** * 將內容回寫到文件中 * * @param filePath * @param content */ public static void write(String filePath, String content) { BufferedWriter bw = null; try { // 根據文件路徑創建緩沖輸出流 bw = new BufferedWriter(new FileWriter(filePath)); // 將內容寫入文件中 bw.write(content); } catch (Exception e) { e.printStackTrace(); } finally { // 關閉流 if (bw != null) { try { bw.close(); } catch (IOException e) { bw = null; } } } } }
C. 如何通俗地理解 Gradle
漢下 白 登 道
D. build.xml是什麼
1、ant的配置文件,用於打包發布,裡面含有配置文件。有點類似於linux/unix下的makefile。
(1)build.xml就是一個XML文件,它包含一個project節點和至少一個target節點,target節點包含多個task元素。簡單說,target節點代表著你的構建目標,而該目標是由多個操作/任務(task)來達成的。
(2)文字描述比較枯燥,下面以簡單的java項目為例,說明如何通過ant發布jar包。
在eclipse中新建一個java項目,結構如下
2、ant
(1)Apache Ant,是一個將軟體編譯、測試、部署等步驟聯系在一起加以自動化的一個工具,大多用於Java環境中的軟體開發。由Apache軟體基金會所提供。
(2)Ant的優點
A、Ant是Apache軟體基金會JAKARTA目錄中的一個子項目,它有以下的優點。跨平台性。Ant是存Java語言編寫的,所示具有很好的跨平台性。操作簡單。Ant是由一個內置任務和可選任務組成的。Ant運行時需要一個XML文件(構建文件)。Ant通過調用target樹,就可以執行各種task。
B、每個task實現了特定介面對象。由於Ant構建文件時XML格式的文件,所以和容易維護和書寫,而且結構很清晰。Ant可以集成到開發環境中。由於Ant的跨平台性和操作簡單的特點,它很容易集成到一些開發環境中去。
(3)Ant 開發
Ant的構建文件:當開始一個新的項目時,首先應該編寫Ant構建文件。構建文件定義了構建過程,並被團隊開發中每個人使用。Ant構建文件默認命名為build.xml,也可以取其他的名字。只不過在運行的時候把這個命名當作參數傳給Ant。構建文件可以放在任何的位置。一般做法是放在項目頂層目錄中,這樣可以保持項目的簡潔和清晰。
E. 用ant腳本執行sql語句
兩步即可:
1.將執行sql語句的命令寫在一個 xx.bat文件裡面
2.在build.xml腳本里 使用 exec標簽來執行bat文件即可
例如:<exec executable=" xx.bat" ></exec>
你們資料庫是什麼資料庫呢?如果是oracle資料庫,那麼執行sql語句的命令是用 sqlplus user/pwd@db example.sql
關於ant腳本標簽,請參考:http://hi..com/woxfy/blog/item/8359887a281899fe0ad1878d.html
F. 如何在Jenkins Ant腳本中使用正則表達式
如何在Jenkins Ant腳本中使用正則表達式
if (savedInstanceState == null) {
// We were just launched -- set up a new game
mSnakeView.setMode(SnakeView.READY);
} else {
// We are being restored
Bundle map = savedInstanceState.getBundle(ICICLE_KEY);
if (map != null) {
mSnakeView.restoreState(map);
} else {
mSnakeView.setMode(SnakeView.PAUSE);
}
}
}
並重寫onSavedInstanceState(),此方法會在activity結束時,調用.
@Override
public void onSaveInstanceState(Bundle outState) {
//Store the game state
outState.putBundle(ICICLE_KEY, mSnakeView.saveState());
}
G. ant是用來干什麼的
Apache Ant,是一個將軟體編譯、測試、部署等步驟聯系在一起加以自動化的一個工具,大多用於Java環境中的軟體開發。
Ant運行時需要一個XML文件, Ant通過調用target樹,就可以執行各種task。每個task實現了特定介面對象。
由於Ant構建文件 是XML格式的文件,所以很容易維護和書寫,而且結構很清晰。Ant可以集成到開發環境中。由於Ant的跨平台性和操作簡單的特點,它很容易集成到一些開發環 境中去。
(7)ant腳本if擴展閱讀
Ant的depends屬性指定了target的執行順序。Ant會依照depends屬性中target出現順序依次執行 每個target。
在執行之前,首先需要執行它所依賴的target。程序中的名為run的target的 depends屬性compile,而名為compile的target的depends屬性是prepare,所以這幾個target執 行的順序是prepare->compile->run。
一個target只能被執行一次,即使有多個target依賴於它。如果沒有if或unless屬性target總 會被執行。
參考資料來源:網路-apache ant
H. 關於JAVA,誰知道這是怎麼回事啊,在代碼if(ant_flag=="true") flag=true;中,我讀出來ant_flag是true
字元串值的比較要用equals,用==只能比較兩者的內存地址,當然不相等啦
if(ant_flag.equals("true"))
I. 如何在Ant中使用邏輯判斷比如判斷文件是否存在
好久不寫ant腳本了,最近兩天在用ant做web應用的安裝部署腳本,為了實現web伺服器的多版本兼容,必然要使用邏輯判斷,比如我要判斷是安裝在weblogic8上還是weblogic9上,而在ant中處理邏輯判斷真是麻煩,只能作用於task,要利用property來做判斷,使用available來設置property。例如:
<?xml version="1.0" encoding="GB2312"?>
<project name="weblogic ant task" default="build">
<target name="detect.file" >
<condition property="fileIsExists" >
<and>
<available file="c:/123.txt"/>
</and>
</condition>
</target>
<target name="echoDemo" if="fileIsExists" depends="detect.file">
<echo message="hello ant"/>
</target>
<target name="build">
<antcall target="echoDemo"/>
</target>
</project>
上面判斷一個文件,如果存在的話 fileIsExists 就為true,echoDemo這個task在執行前會先判斷fileIsExists 是否為true如果不為true就不執行了。c盤下面有123.txt的話會列印hello ant 否則不會列印。
這裡面還有一個小陷阱,我習慣使用antcall,不喜歡使用depends,但是使用antcall的話就會有問題,例如我最開始這么寫的,就不行。
<?xml version="1.0" encoding="GB2312"?>
<project name="weblogic ant task" default="build">
<target name="detect.file">
<condition property="fileIsExists">
<and>
<available file="c:/123.txt"/>
</and>
</condition>
</target>
<target name="echoDemo" if="fileIsExists">
<echo message="hello ant"/>
</target>
<target name="build">
<antcall target="detect.file"/>
<antcall target="echoDemo"/>
</target>
</project>
使用antcall的話在echoDemo這個task執行的時候fileIsExists這個屬性永遠不為true,即便在執行完detect.file後它已經為true了,但是它不會被傳遞到下一個task,沒用深入研究過ant,所以具體內部實現還不了解。
下面是ant的官方參考文檔
更復雜的可以參考
http://ant.apache.org/manual/CoreTasks/conditions.html