zoukankan      html  css  js  c++  java
  • JAR API

    JAR API包括使用 manifest 文件的类。Manifest类的一个对象表示一个manifest文件。 在代码中创建一个Manifest对象,如下所示:

    1
    Manifest manifest = new Manifest();

    可以从manifest文件中读取条目并向其写入条目。要将一个条目添加到主部分,使用Manifest类中的getMainAttributes()方法获取Attributes类的实例,并使用其put()方法继续向其添加名称/值对。

    以下代码将一些属性添加到manifest对象的主部分。已知的属性名称在Attributes.Name类中定义为常量。

    例如,常量Attributes.Name.MANIFEST_VERSION表示manifest版本属性名称。

    1
    2
    3
    4
    5
    Manifest manifest = new Manifest();
    Attributes  mainAttribs = manifest.getMainAttributes(); 
    mainAttribs.put(Attributes.Name.MANIFEST_VERSION, "1.0"); 
    mainAttribs.put(Attributes.Name.MAIN_CLASS, "cn.sxt.Main");
     mainAttribs.put(Attributes.Name.SEALED, "true");

    将单个条目添加到manifest文件比添加到主条目稍微复杂一点。以下代码显示如何向Manifest对象添加单个条目:

    1
    2
    3
    4
    5
    Map<String,Attributes> attribsMap = manifest.getEntries();
    Attributes attribs  = new Attributes();
    Attributes.Name name = new Attributes.Name("Sealed");
    attribs.put(name, "false");
    attribsMap.put("cn/sxt/archives/", attribs);

    要将manifest文件添加到JAR文件,请在JarOutputStream类的一个构造函数中指定它。例如,以下代码创建一个jar输出流,以使用Manifest对象创建一个test.jar文件:

    点击链接查看详细内容

  • 相关阅读:
    函数参数太多的一种简化方法
    laravel 获取所有表名
    使用 laravel 的 queue 必须知道的一些事
    git "refusing to merge unrelated histories" 解决方法
    使用 xhprof 进行 php 的性能分析
    php 性能优化
    js原生实现轮播图效果(面向对象编程)
    nextSibling 和nextElementSibling
    如何在页面中使用svg图标
    svg动画 animate
  • 原文地址:https://www.cnblogs.com/hane/p/7306513.html
Copyright © 2011-2022 走看看