如何在 Eclipse 中使用自己的 MANIFEST.MF 构建 jar

发布于 2024-10-05 04:52:07 字数 355 浏览 1 评论 0原文

我在 Eclipse 中的 java 项目中有一个自定义的 MANIFEST.MF。

将项目导出到jar时,我选择

使用工作区中的现有清单

提取 .jar 显示 eclipse 生成了自己的清单。

我的清单:

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

我该如何解决这个问题?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

古镇旧梦 2024-10-12 04:52:07

您可以使用 build.xml 来构建 jar 文件。

然后您只需将 build.xml 作为 Ant 任务运行即可。

请参阅 alt text

如果您希望 build.xml 在每次构建 Eclipse 项目时自动运行,您可以将其添加到建设者名单。

请参阅 alt text

下面是使用自定义清单的示例 build.xml:

<?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>

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>
少跟Wǒ拽 2024-10-12 04:52:07

在 Eclipse 3.6.1 中。
右键单击您编译的项目 ->出口
接下来,您应该从树中选择 Java - JAR File
在选择选项后出现的新表单中,不要单击“完成”,而是单击“下一步”。
第三种形式是'JAR Manifest Specific',您可以在其中选择您的清单文件而不是 eclipse 生成的文件。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文