代码之家  ›  专栏  ›  技术社区  ›  Maurice Perry

Netbeans清单

  •  20
  • Maurice Perry  · 技术社区  · 16 年前

    是否可以将条目添加到netbeans生成的jar的manifest.mf文件中?

    例如,构建一个OSGi包。

    8 回复  |  直到 7 年前
        1
  •  18
  •   Peter    14 年前

    请注意,您可以通过Ant任务动态创建清单,并动态设置属性。

    首先,必须更新“nbproject”目录中的netbeans“project.properties”文件。将以下行添加到文件:

    manifest.file=manifest.mf
    

    接下来,创建一个Ant任务,使用“build.xml”文件创建/更新清单。在本例中,我们将设置JAR文件的版本号和日期。

    <target name="-pre-init">
       <property name="project.name" value="My Library" />
       <property name="version.num" value="1.4.1" />
       <tstamp>
          <format property="NOW" pattern="yyyy-MM-dd HH:mm:ss z" />
       </tstamp>
    
       <!--
       <exec outputproperty="svna.version" executable="svnversion">
           <arg value="-c" />
           <redirector>
               <outputfilterchain>
                   <tokenfilter>
                       <replaceregex pattern="^[0-9]*:?" replace="" flags="g"/>
                       <replaceregex pattern="M" replace="" flags="g"/>
                   </tokenfilter>
               </outputfilterchain>
           </redirector>
       </exec>
       -->
    
    
       <manifest file="MANIFEST.MF">
          <attribute name="Bundle-Name" value="${project.name}" />           
          <attribute name="Bundle-Version" value="${version.num}" />
          <attribute name="Bundle-Date" value="${NOW}" />
          <!--<attribute name="Bundle-Revision" value="${svna.version}" />-->
          <attribute name="Implementation-Title" value="${project.name}" />
          <attribute name="Implementation-Version" value="${version.num}" />
          <attribute name="Implementation-URL" value="http://www.example.com" />
       </manifest>
    
    </target>
    

    这将在您的netbeans项目目录中创建一个清单文件,并将其放入JAR文件中。如果要从NetBeans项目目录中删除自动生成的清单文件,只需创建另一个Ant任务(当然是post-jar):

    <target name="-post-jar">
      <delete file="MANIFEST.MF"/>
    </target> 
    
        2
  •  6
  •   java.is.for.desktop    16 年前

    这里可能有一些有趣的信息:

    http://wiki.netbeans.org/FaqNoMainClass

        3
  •  2
  •   gazzamop    15 年前

    我有一个带有自定义清单文件的Java类库项目——对于OSGi束来说是完美的。要获取此工作,请先编辑project.properties并设置:

    manifest.file=manifest.mf
    manifest.available=true
    

    在项目目录中创建自己的自定义manifest.mf文件。

    (此时,如果尝试清理/构建,您仍然无法获得自定义清单文件-NetBeans将提供自己的清单文件。这是因为build-impl.xml ant目标“-do jar with libraries without manifest”在“-do jar with manifest”之后立即被调用,用默认的netbeans manifest jar覆盖您的自定义manifest jar文件。)

    将自定义目标添加到build.xml文件,如下所示:

    <target name="-do-jar-with-libraries-without-manifest">
        <!-- Inserted to prevent target from running so we can have a custom
             manifest file with a class library project type. -->
    </target>
    

    在Netbeans 6.7.1中测试

        4
  •  1
  •   Houtman    16 年前

    与build.xml在同一目录中 您可以将manifest.mf文件

    我用的是NetBeans 6.7.1 结果发现build-imp.xml(实际的构建脚本netbeans使用)

    • 没有运行if“with manifest,without main class”的目标
    • 但它确实有一个类似“with manifest,with main class”

    所以…确保项目属性、运行、主类都填充了-anything-

    我认为这是一些未记录的特征:(

    这是我的清单内容:

    Manifest-Version: 1.0
    X-COMMENT: Main-Class will be added automatically by build
    Bundle-ManifestVersion: 2
    Bundle-Name: jinstall
    Bundle-SymbolicName: jinstall
    Import-Package: ( .... )
    Export-Package: ( .... )
    Bundle-Activator: ( ..... )
    
        5
  •  1
  •   Lukino    12 年前

    如果您使用maven(nbm maven插件),请看这个

    NBM Maven plugin

        6
  •  0
  •   Karussell    16 年前

    为什么不使用一个对我很好的Maven项目呢?例如。 apache felix

    this pluggable Swing example 我用Netbeans创建的。

        7
  •  0
  •   czdepski    7 年前

    您可以编辑 nbproject/build-impl.xml 添加必要的属性,如:

    ....
    <target depends="init,-do-jar-create-manifest,-do-jar-copy-manifest" if="do.archive+main.class.available" name="-do-jar-set-mainclass">
        <manifest encoding="UTF-8" file="${tmp.manifest.file}" mode="update">
            <attribute name="Main-Class" value="${main.class}"/>
            <attribute name="Property1" value="foo"/>
            <attribute name="Property2" value="bar"/>
        </manifest>
    </target>
    ....
    

    这将导致 MANIFEST.MF 在这样的JAR文件中:

    Manifest-Version: 1.0
    ...
    Property1: foo
    Property2: bar
    

    在Netbeans 8.1上测试。

        8
  •  -2
  •   ivan_ivanovich_ivanoff    16 年前

    this article .

    这里描述了如何

    • 创建自己的蚂蚁目标
    • 在manifest.mf中为输出jar添加手动条目
    • 从NetBeans运行自定义Ant目标
    推荐文章