简体   繁体   English

构建jar并包含库jar

[英]Build jar and include library jar

I am using Eclipse. 我正在使用Eclipse。

I wrote a little Java Gui Tool that depends on the jnetpcap libary which is included in my eclipse project. 我写了一个小的Java Gui工具,它取决于我的eclipse项目中包含的jnetpcap库。 On my disk the library is placed in a differenct directory than the project. 在我的磁盘上,库位于与项目不同的目录中。

I want to build a jar ( export-> jar ) to have it run on other computers, but I did not find out how to "include" the jar file. 我想构建一个jar( export-> jar )让它在其他计算机上运行,​​但我没有找到如何“包含”jar文件。

I don't mind if it's merged into one file or the library is shipped separately. 我不介意它是否合并到一个文件或库是单独发货。 I just don't know what to configure and where, to have a complete build of that dependency. 我只是不知道要配置什么,以及在哪里,完整构建该依赖项。

There's no out-of the box way to do this, but there are tools that provide jar dependency inclusion. 没有现成的方法可以做到这一点,但有些工具可以提供jar依赖项。

Jarjar and one-jar come to mind. 脑海 浮现出Jarjar一罐 Both provide ant tasks and the latter has a maven plugin. 两者都提供了ant任务,后者有一个maven插件。

If you're using eclipse, when creating executable jar the dependencies get included automatically AFAIK. 如果您正在使用eclipse,那么在创建可执行jar时,依赖项会自动包含在AFAIK中。

I would strongly recommend that you look at build tools like Ant or Maven. 我强烈建议您查看Ant或Maven等构建工具。 They are defacto standard for Java projects and will help you to achieve such tasks. 它们是Java项目的事实标准,将帮助您完成此类任务。

Look at this link: http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html 请看这个链接: http//maven.apache.org/guides/getting-started/maven-in-five-minutes.html

It will basically take 5 minutes of your time to understand the basic principles of Maven and perhaps 30 more to know how to use a plugin to to exactly what you want. 基本上花费5分钟的时间来理解Maven的基本原理,或者还有30多个时间来了解如何使用插件来完全满足您的需求。 If I had known five years ago about Maven it would literally saved weeks of my time. 如果我在五年前就已经了解过Maven,那么我几乎可以节省数周的时间。

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

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