开发者

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

开发者 https://www.devze.com 2023-01-27 14:30 出处:网络
I have a custom MANIFEST.MF in my java-project in Eclipse. When exporting the project to a jar, I choose

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?


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

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

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

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

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>


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号