5

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?

Sven
  • 111
  • 2
  • 2
  • 5

2 Answers2

4

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>
Koekiebox
  • 5,793
  • 14
  • 53
  • 88
0

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.

darwin
  • 354
  • 2
  • 2
  • As posted, that is exactly what I did. I'm using Eclipse 3.3.2. – Sven Dec 01 '10 at 11:19
  • Well, this option DOES work (in Eclipse Luna). Just make sure you add a hard return after the last manually added option in your custom MANIFEST.MF otherwise the parser won't notice the last line. In my case this made it look like the option was not working altogether – DataHacker Dec 18 '14 at 10:01