Is it possible to add a custom manifest to a Java library compiled in Netbeans 6.7.1?

ε祈祈猫儿з 提交于 2019-12-07 16:17:05

问题


I tried adding manifest.file=${src.dir}/manifest.mf to project.properties, but looking through the build-impl.xml I see that the manifest.available is usually accompanied by main.class condition, so it makes me believe that my manifest would be added only if the package has a main class, which mine, being a library, does not have. No matter what I tried, the resulting library jar contains just the auto-generated manifest with only Ant-Version and Created-By.


回答1:


I ended up adding a Jar task in the build.xml, which was really good since it allowed me to add a Sign task also after the manifest update:

<target name="-post-jar">
    <jar destfile="${dist.jar}"
        update="true">
       <manifest>
         <attribute name="Built-By" value="..."/>
         <attribute name="Specification-Title" value="..."/>
         <attribute name="Specification-Vendor" value="..."/>
         <attribute name="Specification-Version" value="..."/>
         <attribute name="Implementation-Vendor" value="..."/>
         <attribute name="Implementation-Title" value="..."/>
         <attribute name="Implementation-Version" value="..."/>
       </manifest>
    </jar>
    <signjar jar="${dist.jar}"
        alias="..."
        keystore="..."
        storepass="..."/>
</target>



回答2:


To get an easy to edit MANIFEST.MF a modification of the above is to override the "-post-jar" task in build.xml like:

<target name="-post-jar">
        <jar destfile="${dist.jar}"
        update="true" manifest="src/META-INF/MANIFEST.MF">
        </jar>
</target>

and to create the package "META-INF" (may also be used for other adjustments like a "mime.types" file) and therein an empty file named "MANIFEST.MF", which then can be edited inside the NetBeans editor, for example containing:

Manifest-Version: 1.0
Foo: Bar
See: Jar_File_Spec

This way tested with:
Product Version: NetBeans IDE 6.9.1 (Build 201011082200)
Java: 1.6.0_21; Java HotSpot(TM) 64-Bit Server VM 17.0-b16
System: Linux version 2.6.32-29-generic running on amd64; UTF-8; de_DE (nb)



来源:https://stackoverflow.com/questions/1598229/is-it-possible-to-add-a-custom-manifest-to-a-java-library-compiled-in-netbeans-6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!