简体   繁体   English

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

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

I wrote my Java application in Eclipse. 我在Eclipse中编写了Java应用程序。 Now I would like to generate a .jar file which can be run on other systems from the command line. 现在我想生成一个.jar文件,该文件可以从命令行在其他系统上运行。 Is there a easy way to do it in Eclipse? 在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. 我在窗口中可以选择“将所需的库提取到生成的JAR中”或“将所需的包打包到生成的JAR中”等等。 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. 每个配置都与命令行中给出的一组固定参数相关联,我不希望这样。

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

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. 当你去Export => Java => Runnable JAR file ,你说“Next”按钮还没有激活,你不必按下一个按钮,因为你可以按完成,如果你不想要Lauch配置,您可以稍后手动编辑清单文件。 If you have external libraries you can chose one of the options they give you, extract/package/copy required libraries into jar file 如果您有外部库,则可以选择其中一个选项,将所需的库提取/打包/复制到jar文件中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM