--- title: Eclipse | export / clean up Launch configuration tags: Java, Runnable Jar, clean up Configaration --- Eclipse | export / clean up Launch configuration === ###### tags: `Java` `Runnable Jar` `clean up Configaration` > **「 ... XX飛機於X月X日墜毀於XX洋...距深度打撈約為1000多公尺處,確切偵獲黑盒子信號... 」** > >類似事件偶而在新聞上播出,重上述中可以發現,每次墜毀事件皆要求要打撈出**黑盒子** >而在程式開發人員心中, **Jar包地位** == 黑盒子重要性 **(極為重要)** ## :memo: 認識 Jar 包 Jar包全名為 Java Archive File,顧名思義就是與java有關且可多個文件合而為一呈現 而Jar包與zip包相似,唯一不同點在於Jar包內包含了一個 META-INF/MANIFEST.MF 文件 其 MANIFEST.MF文件內含重要Class-Path/Main-Class,決定了這個jar包主要執行的main程式 --- ### Ⅰ. IDE --- Jar打包 **<font size =4 color=Silver><center>--以下是由Eclipse IDE進行打包--</center></font>** **A \) 執行Eclipse IDE,並對需要包裝的主程式<專案> Export產出** ![](https://i.imgur.com/SKlGLHw.png) &nbsp; &nbsp; **B \)選取 Java/Runnable JAR file** ![](https://i.imgur.com/B1TQSGx.png) &nbsp; &nbsp; C \)選擇需求的 Launch configuration / Export destination ![](https://i.imgur.com/IWPiFKA.png) &nbsp; ::: info :bulb:重點: 需打包的code必須compiler,才會在Launch configuration出現 &emsp;&emsp;&emsp;&emsp;&ensp;&nbsp;而有改動的code也必須compiler,不然在Launch configuration中出現為**未更動狀態** ![](https://i.imgur.com/7NeAedv.png) ::: E ) 最後選擇包裝方式 Library handling ![](https://i.imgur.com/oQ8ZXkM.png) Library handling 分成以下三種: - [ ] Extract required libraries into generated JAR <font color="red">將使用的 library / Jar包 一同包裝在Jar檔,但存取的部分**只有.class檔**包裝在內</font> - [ ] Package required libraries into generated JAR <font color="red">將使用的 library / Jar包 一同包裝成Jar檔,與Extract 功能不同的地方為 :arrow_right: Package是將整使用到的Jar包打包,而**非.class檔**存取</font> - [ ] Copy required libraries into a sub-folder next to the generated JAR <font color="red">如字面意思,提取程式**需要的library / Jar包**,另外用**sub-folder**區隔並放在同路徑下 而運行的Jar包內僅含有 **.class** 的應用文件</font>. :::info :bulb: 缺點檢討 第一、二項:當應用程式更新,則用戶就必須下載全新安裝檔以更新數據 &emsp;&emsp;第三項:因為是Jar檔與library分開包裝,用戶只要下載更新的程式代碼 &emsp; :arrow_right: **選項2** 可以將所有內容整齊地打包成單個Jar,並將引用的 Jar檔 與.class文件分開(較推薦) ::: --- ### Ⅱ. 清理 Launch Configuration 當Compiler過多後,Launch configuration會產生過多"無用"的程式檔 必要時須清理Lauch configuration的檔案,以避免混亂 &nbsp; **A \) 進到Lauch configuration存放位置** **&emsp;&ensp;&nbsp;路徑為 :arrow_right: eclipse-work \> .metadata \> .plugins \> org.eclipse.debug.core \> .launches** <img src="https://i.imgur.com/hK2pAmw.png"/> &nbsp; B \) 清空.launches所有包含物 **\<即代表清空Launch configurattion\>** <img src="https://i.imgur.com/HGD3aE7.png"/> --- |參考網站|連結| |---|---| |Eclipse: How to Clean Up Launch Configurations| [:link:][Eclipse: How to Clean Up Launch Configurations] | |What is the difference between runnable jar library handling options?|[:link:][What is the difference between runnable jar library handling options?]| [Eclipse: How to Clean Up Launch Configurations]: https://www.youtube.com/watch?v=TgpgE4zICQM [What is the difference between runnable jar library handling options?]: https://stackoverflow.com/questions/8302894/what-is-the-difference-between-runnable-jar-library-handling-options <style> table td{ width: 100%; } table th:first-of-type { width: 80%; } table th:nth-of-type(2) { width: 20%; } </style>