訪問JAR和JAD檔案中的屬性

來源:互聯網
上載者:User

MIDIet能夠訪問Java壓縮包(*.JAR)和應用程式描述項檔案(*.JAD)中的屬性(attributes),你可以按照以下代碼實現:
  
  javax.microedition.midlet.MIDlet.getAppProperty(String name)
  
  以下舉一個非常簡單的例子來列印JAR跟JAD檔案中的條目:
  
  import javax.microedition.midlet.*;
  
  public class showProperties extends MIDlet
  {
  public void startApp() throws MIDletStateChangeException
  {
  System.out.println("Vendor: " +
  getAppProperty("MIDlet-Vendor"));
  System.out.println("Description: " +
  getAppProperty("MIDlet-Description"));
  System.out.println("JadFile Version: " +
  getAppProperty("JadFile-Version"));
  System.out.println("MIDlet-Data-Size: " +
  getAppProperty("MIDlet-Data-Size"));
  }
  
  public void pauseApp()
  { }
  
  public void destroyApp(boolean unconditional)
  { }
  }
  
  manifest.mf 檔案儲存體在ShowProperties.jar 檔案中:
  MIDlet-Name: Show Properties MIDlet
  MIDlet-Version: 1.0.1
  MIDlet-Vendor: Core J2ME
  MIDlet-1: ShowProps, , ShowProperties
  MicroEdition-Profile&: MIDP-1.0
  MicroEdition-Configuration: CLDC-1.0
  MIDlet-Description: A simple property list example
  MIDlet-Data-Size: 1500
  
  ShowProperties.jad 檔案
  MIDlet-Name: Show Properties MIDlet
  MIDlet-Version: 1.0.1
  MIDlet-Vendor: Core J2ME
  MIDlet-Jar-URL: ShowProperties.jar
  MIDlet-Jar-Size: 1190
  MIDlet-1: ShowProps, , ShowProperties
  MIDlet-Description: A simple property list example
  JadFile-Version: 1.5
  MIDlet-Data-Size: 500
  
  要點:
  1.manifest.mf檔案儲存體在JAR檔案中,那是你實際可以訪問的屬性(attributes)。
  2.ShowProperties.jad 檔案中引用了這個JAR檔案:
  MIDlet-Jar-URL: showProperties.jar
  3.這些屬性包括:MIDlet-Name,MIDlet-Version,MIDlet-Vendor既存在於JAR檔案中的manifest.mf中又存在於JAD檔案中,所有的值都要求是一樣的。
  4.屬性(attribute)JadFile Version是使用者自訂的屬性,並沒有在J2ME規格中定義。這樣就可以被MIDIet程式訪問而不用修改JAR檔案。
  5.屬性(attribute)MIDlet-Data-Size同時存在於manifest.mf和JAD檔案中。當存在於兩個檔案中的屬性一樣時,JAD檔案中的會被優先選擇。
  6.以上例子是基於MIDP和CLDC 1.0.3.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.