简体   繁体   中英

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

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.

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>

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM