Sven
Sven

Reputation: 111

How to build a jar using an own MANIFEST.MF in Eclipse

I have a custom MANIFEST.MF in my java-project in Eclipse.

When exporting the project to a jar, I choose

Use existing manifest from workspace

Extracting the .jar shows that eclipse generated its own manifest.

My manifest:

Manifest-Version: 1.0 
Main-Class: de.somehow.tagPDF.Main
Class-Path: lib/iText-5.0.2.jar;lib/jxl.jar;lib/jai_codec.jar;lib/jai_core.jar

How can I fix this?

Upvotes: 5

Views: 15907

Answers (2)

darwin
darwin

Reputation: 364

In eclipse 3.6.1. Rigth click on your compiled project -> Export Next you should choose Java - JAR File from the tree In new form appeared after you select options don't click finish but 'Next'. Third form will be 'JAR Manifest Specification' and there you can choose your manifest file instead of eclipse generated one.

Upvotes: 0

Koekiebox
Koekiebox

Reputation: 5963

You can make use of a build.xml to build the jar file for you.

Then you just run the build.xml as a Ant task.

See alt text

If you want the build.xml to run automatically every time you build your Eclipse project, you can add it to the Builders list.

See alt text

Below is a sample build.xml where a custom manifest is used:

<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." name="Example" default="run_build">

    <property name="guiJar" value="../../Library/<jar-name>.jar"></property>

    <target name="run_build" depends="delete_old_jar,create_dirs,create_manifest,copy_all_class_files,create_jar,delete_temp_dirs">
    </target>

    <target name="delete_old_jar">
        <delete file="${guiJar}">
        </delete>
    </target>

    <target name="create_dirs">
        <mkdir dir="jar_temp" />
        <mkdir dir="jar_temp/META-INF" />
    </target>

    <target name="delete_temp_dirs">
        <delete dir="jar_temp">
        </delete>
    </target>

    <target name="create_manifest">
        <manifest file="jar_temp/META-INF/MANIFEST.MF">
            <attribute name="Manifest-Version" value="1.0" />
            <attribute name="Version" value="1.0.0" />
            <attribute name="Company" value="Value" />
            <attribute name="Project" value="Value" />
            <attribute name="Java-Version" value="${java.version}" />
            <attribute name="Class-Path" value="test.jar" />
                    <attribute name="Main-Class" value="com.Main" />
        </manifest>
    </target>

    <target name="create_jar">
        <jar destfile="${guiJar}" manifest="jar_temp/META-INF/MANIFEST.MF" basedir="jar_temp">
        </jar>
    </target>

    <target name="copy_all_class_files">
        <copy todir="jar_temp">
            <fileset dir="classes">
                <include name="*/**" />
            </fileset>
        </copy>
    </target>
</project>

Upvotes: 4

Related Questions