德國開源項目,J2ME 開發的「預處理器 + 構建框架 + 設備庫」。解決核心痛點:
Manager.createPlayer(is, "audio/midi")new Sound(400,1000).play(1)維護多套源碼,或運行時 if-else 判斷 (增加體積、降低性能)。
// 源碼中嵌入預處理指令 (以 //# 開頭)
//#if polish.midp2 || polish.api.mmapi
try {
InputStream is = getClass().getResourceAsStream("/mymid.mid");
Player player = Manager.createPlayer(is, "audio/midi");
player.realize(); player.start();
} catch (MediaException me) {
//#debug error
System.out.println("Unable to play midi: " + me);
} catch (IOException ioe) {
//#debug error
System.out.println("Unable to load midi: " + ioe);
}
//#elif polish.api.nokia-ui
Sound s = new Sound(400, 1000);
s.setGain(100);
s.play(1);
//#endif
//#if condition、//#elif condition、//#else、//#endif:條件編譯,語法同 C/C++。//#debug level:調試輸出控制 (error、warn、info、debug),構建時可過濾級別。polish.midp2、polish.api.mmapi、polish.api.nokia-ui、polish.ScreenWidth、polish.HeapSize 等數百個預定義變量,覆蓋平台、API、硬件特性。<!-- build.xml 片段 -->
<property name="polish.dir" location="../j2mepolish"/>
<import file="${polish.dir}/build.xml"/>
<target name="build-all">
<polish.emulator
devices="Nokia/Series40, Generic/midp2"
>
<requirement name="Identifier" value="Nokia/Series40,Generic/midp2"/>
</polish.emulator>
</target>
devices 指定目標設備組 (來自 devices.xml 數據庫,含數千機型特性)。//#debug 指令配合構建參數,實現「開發版含詳細日誌、發布版零開銷」。samples/ 目錄完整項目結構。devices.xml 理解設備能力描述模型。polish.task,嘗試雙設備構建。//#if、//#debug、//#define 等指令,重構現有條件編譯邏輯。J2ME Polish 為 Java 引入了「編譯時預處理 + 設備感知構建」能力,**徹底解決了「一碼多端、差異化優化、自動化發布」的工程化難題**,是中大型 J2ME 專案、產品線開發的標配利器。