Java 如何使用自定义清单文件在 Eclipse 中构建 JAR?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1106467/
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 do you build a JAR in eclipse with a custom manifest file?
提问by Robert Greiner
I am trying to to build a Felix bundle in Eclipse. This basically includes having Eclipse create a JAR (through export) and adding my custom manifest file, however, I can't seem to get this to work. When I try exporting a JAR file, my custom manifest file shows up in the JAR, but doesn't ever get added to the right location within the JAR (meta-inf). This causes another default manifest file, which is created by Eclipse, to be added to my JAR file.
我正在尝试在 Eclipse 中构建一个 Felix 包。这基本上包括让 Eclipse 创建一个 JAR(通过导出)并添加我的自定义清单文件,但是,我似乎无法让它工作。当我尝试导出 JAR 文件时,我的自定义清单文件显示在 JAR 中,但从未添加到 JAR 中的正确位置(元信息)。这会导致将 Eclipse 创建的另一个默认清单文件添加到我的 JAR 文件中。
Note:I am using Eclipse's built in JAR export tool and selecting the option to use an existing manifest file from my workspace.
注意:我正在使用 Eclipse 的内置 JAR 导出工具,并选择使用工作区中现有清单文件的选项。
I'm sure there is some small detail being overlooked, but I am a little stumped.
我敢肯定有一些小细节被忽略了,但我有点难住了。
Thanks for your help.
谢谢你的帮助。
采纳答案by Eugene Yokota
See Java Course - Creating a Java Application with Eclipsefor doing it from UI.
请参阅Java 课程 - 使用 Eclipse 创建 Java 应用程序以从 UI 执行此操作。
You could also run Ant's jar taskfrom Eclipse.
您还可以从 Eclipse运行 Ant 的jar 任务。
<target name="jar" depends="compile">
<mkdir dir="${jar.dest}" />
<jar
manifest="manifest.txt"
jarfile="${build.jar}"
basedir="${build.dest}">
</jar>
</target>
Edit: For OSGi bundles, there's Bnd, the bundle tool by Peter Kriens. That'll generate manifest and build jar for you. The tool is capable as acting as command line tool as well as Ant, Maven, and Eclipse plugin.
编辑:对于 OSGi 包,有Bnd,Peter Kriens 的包工具。这将为您生成清单并构建 jar。该工具既可以充当命令行工具,也可以充当 Ant、Maven 和 Eclipse 插件。
回答by Benoit Courtine
IF you use the Maven plugin (m2clipse), you can precise the manifest file in the maven configuration file of your project (pom.xml), in the "build section".
如果您使用 Maven 插件 (m2clipse),您可以在项目的 Maven 配置文件 (pom.xml) 中的“构建部分”中精确显示清单文件。
The manifest file will be added to the jar when you build it with maven (goal "mvn package").
当您使用 maven(目标“mvn package”)构建清单文件时,清单文件将被添加到 jar 中。