如何在 Eclipse 中使用自己的 MANIFEST.MF 构建 jar
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4323453/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to build a jar using an own MANIFEST.MF in Eclipse
提问by Sven
I have a custom MANIFEST.MF
in my java-project in Eclipse.
我MANIFEST.MF
在 Eclipse 的 java 项目中有一个自定义。
When exporting the project to a jar, I choose
将项目导出到 jar 时,我选择
Use existing manifest from workspace
使用工作区中的现有清单
Extracting the .jar shows that eclipse generated its own manifest.
提取 .jar 表明 eclipse 生成了它自己的清单。
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?
我怎样才能解决这个问题?
采纳答案by Koekiebox
You can make use of a build.xml to build the jar file for you.
您可以使用 build.xml 为您构建 jar 文件。
Then you just run the build.xml as a Ant task.
然后您只需将 build.xml 作为 Ant 任务运行。
See
看
If you want the build.xml to run automatically every time you build your Eclipse project, you can add it to the Builders list.
如果您希望每次构建 Eclipse 项目时都自动运行 build.xml,您可以将它添加到 Builders 列表中。
See
看
Below is a sample build.xml where a custom manifest is used:
以下是使用自定义清单的示例 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>
回答by darwin
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.
在日食 3.6.1 中。右键单击您编译的项目 -> 导出下一步,您应该从树中选择 Java - JAR 文件在您选择选项后出现的新表单中,不要单击完成而是单击“下一步”。第三种形式是“JAR Manifest Specification”,您可以在那里选择您的清单文件而不是 eclipse 生成的文件。