如何配置 Eclipse 来构建需要外部库的 Java 应用程序?
我想为我正在开发的一个小型 Java 项目使用几个标准的第三方库(例如 Apache 的 log4j)。我知道如何配置我的 IDE、Eclipse,以便这些库在我的开发工作期间可用,但我不知道如何为我的应用程序构建发行版,以便在必要时将这些外部库正确安装在目标中系统。
我见过的一种方法是将这些外部库视为项目内部的库,甚至将它们与真正正在开发的代码一起签入 Git 或 subversion 或其他任何库。
我最不喜欢这种方法的一点是,至少对于我目前正在使用的方法来说,这些外部库的总磁盘占用空间超过了我的应用程序本身占用空间的 10 倍(正如我所说,这是相当小的)并且简单)。
有更好的方法吗?
PS:我听说过 Maven,它应该可以处理这些问题,但对于我在这里处理的相对较小且简单的项目来说,它看起来有点过分了。
I want to use several standard third-party libs (e.g. Apache's log4j) for a small Java project I'm working on. I know how to configure my IDE, Eclipse, so that these libraries are available during my development work, but I don't know how to build the distributions for my app so that, when necessary, these external libraries get properly installed in the target system.
One approach I have seen is to treat these external libraries as if they were internal to the project, even checking them into Git or subversion or whatever along with the code that is truly being developed.
What I most dislike of this approach, at least for what I'm working with at the moment, is that the total disk footprint of these external libraries more than 10x the footprint of my app proper (which, as I said, is pretty small and simple).
Is there a better approach?
PS: I've heard about Maven and that it's supposed to handle these issues, but it looks like overkill for the relatively small and simple project I'm dealing with here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我已经很多年没有在没有 Maven 的情况下构建过 Java 应用程序了。无论大小,有东西为您管理依赖关系都是很棒的。当您真正想要部署到终端服务器并且需要将所有依赖项获取到本地时,依赖插件非常有用。我认为任何项目对于一个简单的 POM 文件来说都不算太小。
I haven't built a java app in years without maven. No matter how big or small, having something manage dependencies for you is great. The dependency plugin is awesome for when you actually want to deploy to an end server and need to get all of your deps local. I don't think any project is too small for a simple POM file.
平心而论,您的问题实际上并不是关于 Eclipse,而是关于项目分发。
正如您所说,简单的解决方案是将这些 jar 包含在 svn/git 中的项目中。
Maven 确实可以提供帮助,而且它也与 Eclipse 具有良好的集成,自然地可以简化部署周期。
我同意你的观点,Maven 可能有点矫枉过正。对于中间解决方案,我会考虑 ivy,也许还有 gradle。 这里有一个关于此主题的非常精彩的演示,标题为“您的下一个成功构建”。
In all fairness, your question is not really about Eclipse but about project distribution.
The plain vanilla solution, as you said, is to include those jars with your project in svn/git.
Maven indeed can help, and it also has good integration with Eclipse too, natually, to ease the deployment cycle.
I agree with you that Maven might be an overkill. For a middle ground solution, I'd look at ivy instead, and maybe gradle too. There is a truly awesome presentation titled "your next successful build" about this topic here.
Maven 非常棒,直到您需要开始与其他人一起进行开发并且没有一个每个人都可以访问的 Maven 存储库为止。仅当您创建当前项目所依赖的模块并且他们需要将该依赖项合并到设置中时,这才会成为问题。
如果没有 Maven 存储库来推送这些更改,它可能会变得混乱。
如果这只是您正在处理的项目,或者您公司内部的项目,那么 Maven 可能是一个好主意,或者如果您仅使用公共 Maven 存储库中已经提供的第三方库。
Maven is great and all until you need to start doing development with others and not having a maven repository that everyone can access. This only becomes a problem when you create a module that your current project depends on and they than need to incorporate that dependency into the setup.
Without having a maven repository to push these changes to it can get messy.
If this is only a project you are working on, or internal to your company than maven might be a good idea or if you are only using third party libraries that are already available in public maven repos.