Showing posts with label jar. Show all posts

How to attach MANIFEST.MF file in jar in/using Netbeans?


Step 1: Open build.xml file in notepad or other editor and paste below code within <project>...</project>
<target name="-pre-init">
        <property name="project.name" value="Name of your llibrary"/>
        <property name="version.num" value="1.4.1"/>
        <tstamp>
            <format pattern="yyyy-MM-dd HH:mm:ss z" property="NOW"></format>
        </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="Codebase" value="*"/>           
            <attribute name="Permission" value="all-permissions"/>
            <attribute name="Application-Library-Allowable-Codebase" value="javaquery.com"/>
            <attribute name="Caller-Allowable-Codebase" value="www.javaquery.com javaquery.com"/>
            <attribute name="Application-Name" value="javaQuery"/>
            <attribute name="Bundle-Name" value="${project.name}"/>           
            <attribute name="Bundle-Version" value="${version.num}"/>
            <attribute name="Bundle-Date" value="${NOW}"/>
            <attribute name="Implementation-Title" value="${project.name}"/>
            <attribute name="Implementation-Version" value="${version.num}"/>
            <attribute name="Implementation-URL" value="http://www.javaquery.com"/>
            <!--<attribute name="Bundle-Revision" value="${svna.version}" />-->
        </manifest>
 </target>

Step 2: Edit your required details in attributes. Uncomment the SVN version code if you want to put SVN version details in MANIFEST.MF file

Step 3: Save build.xml file

Step 4: Set your project as main project in netbeans. Now Go to RUN > Clean and build main project

Step 5: Find your output jar file in dist folder of project.

Other Resources:
How to attach MANIFEST.MF file in jar in/using eclipse?
How to create .jar file in netbeans?

How to attach MANIFEST.MF file in jar in/using eclipse?

Every jar file you create using editor it explicitly attach MANIFEST.MF file in it. That contains basic information of that jar file. I was also generating jar file using editor regardless its MANIFEST.MF file. After major security changes in Java 1.7.0_45 its mandatory to specify some attribute in MANIFEST.MF in Applet jar. But its good practice to add this MANIFEST.MF file with proper information in it, whether its applet or simple jar file.

Step 1: Open up simple notepad or other text editor. Add your required attribute in it and save as "MANIFEST.MF" . Here is all attribute information of MANIFEST.MF file. This is my sample MANIFEST.MF file.
Manifest-Version: 1.0
Codebase: *
Permissions: all-permissions
Application-Library-Allowable-Codebase: *
Caller-Allowable-Codebase: *
Application-Name: Digital Certificate
Ant-Version: Apache Ant 1.8.3
Created-By: 1.6.0_25-b06 (Sun Microsystems Inc.)

Step 2: Copy MANIFEST.MF file in your project's folder.

jar, applet, manifest, eclipse

Step 3: Right click on project / file and click on Export.

jar, applet, manifest, eclipse

Step 4: Select JAR file in dialog box and click Next.

jar, applet, manifest, eclipse

Step 5: Select your output file and its location. And click Next.

jar, applet, manifest, eclipse

Step 6: Click Next in JAR Packaging option.
Step 7: Select "Use existing manifest from workspace" and browse your MANIFEST.MF file and click on finish. 

jar, applet, manifest, eclipse

Other Resources:
How to attach MANIFEST.MF file in jar in/using Netbeans?

This application will be blocked in a future Java security update because the JAR file manifest does not contain the Permissions attribute. Please contact the Publisher for more information.

Applet security


The new Java update "1.7.0_45" shows permission warning in applet. If you want to get rid of that warning you must have MANIFEST.MF file in your applet/jar with attribute called Permissions.

Sample MANIFEST.MF file
Manifest-Version: 1.0
Codebase: *
Permissions: all-permissions
Application-Library-Allowable-Codebase: *
Caller-Allowable-Codebase: *
Application-Name: Digital Certificate
Ant-Version: Apache Ant 1.8.3
Created-By: 1.6.0_25-b06 (Sun Microsystems Inc.)

Other Resources:
How to attach MANIFEST.MF file in jar in/using eclipse?
How to attach MANIFEST.MF file in jar in/using Netbeans?
For more details on MANIFEST attribute: http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/manifest.html