如何使用 Eclipse 创建自洽的 .jar 文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2728283/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 14:41:03  来源:igfitidea点击:

How can I create a self-consistent .jar file with Eclipse?

javaeclipsejar

提问by Roman

I wrote my Java application in Eclipse. Now I would like to generate a .jar file which can be run on other systems from the command line. Is there a easy way to do it in Eclipse?

我在 Eclipse 中编写了我的 Java 应用程序。现在我想生成一个可以从命令行在其他系统上运行的 .jar 文件。有没有一种简单的方法可以在 Eclipse 中做到这一点?

In particular I am wondering what should I do with the jar files of external library that I use (should it be included into my .jar file?).

我特别想知道我应该如何处理我使用的外部库的 jar 文件(它应该包含在我的 .jar 文件中吗?)。

Moreover, should I generate some manifest files?

此外,我应该生成一些清单文件吗?

ADDED:

添加:

I see the window in which I can choose "Extract required libraries into generated JAR" or "Package required libraries into generated JAR" and so on. I select the first option, I specify export destination but "Next" button is not activated yet. What else should I specify. I am offered to launch a configuration but i do not want to. Every configuration is associated with a fixed set of parameters given in the command line and I do not want that.

我看到了一个窗口,我可以在其中选择“将所需的库提取到生成的 JAR 中”或“将所需的库打包到生成的 JAR 中”等等。我选择第一个选项,指定导出目的地,但“下一步”按钮尚未激活。我还应该指定什么。我被要求启动一个配置,但我不想。每个配置都与命令行中给出的一组固定参数相关联,我不希望那样。

回答by b_erb

Select you project, then Export=> Java=> Runnable JAR file

选择你的项目,然后Export=> Java=>Runnable JAR file

You can then choose to extract/package/copy required libraries into your JAR and also select the class, whose main()method should be executed on startup.

然后,您可以选择将所需的库提取/打包/复制到您的 JAR 中,并选择main()应在启动时执行其方法的类。

Then you can execute the generated jar via: java -jar yourjar.jar

然后您可以通过以下方式执行生成的 jar: java -jar yourjar.jar

回答by Tian

When you go to Export => Java => Runnable JAR file, You said "Next" button is not activated yet, You don't have to press the next button because you can just press finish, If you don't want the Lauch Configuration, You can manually edit the manifest file later. If you have external libraries you can chose one of the options they give you, extract/package/copy required libraries into jar file

当你去时Export => Java => Runnable JAR file,你说“下一步”按钮还没有激活,你不必按下一步按钮,因为你可以直接按完成,如果你不想要Lauch配置,你可以手动编辑清单文件之后。如果您有外部库,您可以选择他们给您的选项之一,将所需的库提取/打包/复制到 jar 文件中