[英]Exporting a Java project with external dependencies to a jar using Eclipse
Is there an easy way to export a Java project including all of its external dependencies to a standard .jar file? 有没有简单的方法可以将Java项目(包括其所有外部依赖项)导出到标准.jar文件?
I have developed an SDK that uses several Apache libraries and I would like to be able to ship this project as a single jar. 我已经开发了使用多个Apache库的SDK,并且希望能够将此项目作为一个jar交付。 The answers I have found thus far to this question require the project to be packaged as a Runnable jar, and does not apply to this project which has no main class.
到目前为止,我对这个问题找到的答案要求将项目打包为Runnable jar,而不适用于没有主类的项目。
The rest of the answers I have found assume familiarity with Ant or Maven to accomplish this task, and I have no background with either. 我发现的其余答案都假定您熟悉Ant或Maven来完成此任务,并且我都没有任何背景知识。 There are several scripts out there but I don't understand how I would use/modify them, or what I would to run the script and get a result.
那里有几个脚本,但是我不知道如何使用/修改它们,或者运行脚本并获得结果的方式。
Any answer that can provide more background into how exactly a user with no background with Ant or Maven would do these tasks is greatly appreciated. 能够为无蚂蚁或Maven背景的用户如何完成这些任务提供更多背景的任何答案都将受到极大的赞赏。
For more background information I have trying to combine the following libraries into one called JetstreamSDK.jar 有关更多背景信息,我尝试将以下库合并到一个名为JetstreamSDK.jar的库中
commons-codec-1.6.jar
commons-configuration-1.9.jar
commons-io-2.4.jar
commons-lang-2.6.jar
commons-lang3-3.1.jar
commons-logging-1.1.1.jar
httpclient-4.2.5.jar
httpcore-4.2.4.jar
JetstreamSDK-Java.jar
jibx-bind.jar
jibx-extras.jar
jibx-run.jar
xpp3.jar
jar
file is like zip
compressed file. jar
文件就像zip
压缩文件。 Usually Eclipse (default) java project will be organized like following directory structure: 通常,Eclipse(默认)java项目的组织方式如下所示:
some_project
|____ src/ <--- your java source files
|____ bin/ <--- compiled class files
|____ lib/ <--- 3rd party libs e.g. commons*.jar
To package above structure and distribute as a single jar (zip) file- go inside bin/
directory and select everything inside and just right click (assuming you are working on windows) and send to
compressed (zipped) folder. 要打包以上结构并作为一个jar(zip)文件分发,请进入
bin/
目录,然后选择其中的所有内容,然后右键单击(假设您在Windows上工作),然后send to
压缩(压缩)文件夹。 Give a suitable name to the generated zip file eg your-sdk.jar
then right click on lib/
and compress into a another zip together with your-sdk.jar
and you are done. 给生成的zip文件指定一个合适的名称,例如
your-sdk.jar
然后右键单击lib/
并与your-sdk.jar
一起压缩到另一个zip中,即可完成操作。 This can be accomplished using jar
command line tool also- but, you have to read the jar options/help on how to do this. 也可以使用
jar
命令行工具来完成此操作-但是,您必须阅读jar选项/帮助以了解如何执行此操作。
1.) First compile your project 1.)首先编译您的项目
2.) Right click on your PROJECT -> Export -> Java -> Runnable jar 2.)右键单击您的PROJECT-> Export-> Java-> Runnable jar
3.) You will get a Dialog box, there select the class name (in which your main method resides) 3.)您将看到一个对话框,在其中选择类名称(您的主要方法所在的类)
4.) Give the export destination 4.)给出出口目的地
5.) In library handling(radio button): select your desired option(all are self descriptive) 5.)在库处理中(单选按钮):选择所需的选项(所有都是自描述的)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.