如何使用 Eclipse 中包含的外部库创建 jar? [英] How to create a jar with external libraries included in Eclipse?

查看:33
本文介绍了如何使用 Eclipse 中包含的外部库创建 jar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完成了连接到数据库 (MySQL) 的项目.现在我想将项目导出为 jar.但我不知道如何包含它的外部依赖?有什么办法可以在 Eclipse 中做到这一点,或者我应该为此使用任何脚本吗?.

I am done with the project which connects to database (MySQL). Now I want to export the project as jar. But I don't know how to include its external dependencies? Is there any way of doing it in Eclipse or should I use any scripts for that?.

推荐答案

当您将项目导出为Runnable jar"(在项目上单击鼠标右键 -> 导出 -> Runnable jar)时,您可以选择将所有依赖项打包到生成的罐子.它还有两种其他方式(见截图)来导出你的库,在决定你将使用哪种打包方法时要注意许可证.

When you export your project as a 'Runnable jar' (Right mouse on project -> Export -> Runnable jar) you have the option to package all dependencies into the generated jar. It also has two other ways (see screenshot) to export your libraries, be aware of the licences when deciding which packaging method you will use.

启动配置"下拉列表填充了包含 main(String[]) 方法的类.当您运行"jar 时,选定的类就会启动.

The 'launch configuration' dropdown is populated with classes containing a main(String[]) method. The selected class is started when you 'run' the jar.

导出为可运行的 jar 使用构建路径上的依赖项(右键单击项目 -> 构建路径 -> 配置构建路径...).当您导出为常规"(不可运行)jar 时,您可以选择项目中的任何文件.如果您的项目文件夹中有库,则可以包含它们但外部依赖项,例如 ,不能被包含(对于 maven 项目,在这里搜索).

Exporting as a runnable jar uses the dependencies on your build path (Right mouse on project -> Build Path -> Configure Build Path...). When you export as a 'regular' (non-runnable) jar you can select any file in your project(s). If you have the libraries in your project folder you can include them but external dependencies, for example maven, cannot be included (for maven projects, search here).

这篇关于如何使用 Eclipse 中包含的外部库创建 jar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆