Apache Commons IO 未添加到 jar 中
我最近将 Apache Commons IO 添加到我的一个小项目中,以便我可以跟踪日志文件。在我的 IDE (IntelliJ) 中一切都运行良好,但是当我创建可执行 jar 时,Commons IO 不在那里,所以我得到:
线程“main”中出现异常java.lang.NoClassDefFoundError: org/apache/commons/io/input/TailerListener。
Commons IO 已添加到我的 POM 中:
<依赖>;
commons-io ;commons-io <版本>2.1
我以前从未遇到过像这样添加依赖项的问题。我缺少什么?
I've recently added Apache Commons IO to a small project of mine so that I can tail a log file. Everything works great in my IDE (IntelliJ), but when I create the executable jar, Commons IO isn't in there, so I get :
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/commons/io/input/TailerListener.
Commons IO has been added to my POM:
<dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.1</version> </dependency>
I've never had issues with added dependencies like this before. What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这并不完全是依赖关系的工作方式。依赖项只是告诉其他项目要引入什么。它们不会自动包含在您的 jar 中。
这样做的原因是因为在某些情况下这是浪费的。假设您有两个 jar:a.jar 和 b.jar。两者都依赖于 apache commons。简单地将每个库分开并从公共库目录加载可能会更有效(在空间方面)。
如果你想要一个所谓的“fat jar”(或者任何将所有依赖项放在一个 jar 中的正确术语),你需要使用像这样的插件:
That's not exactly how dependencies work. Dependencies are just there to tell other projects what to pull in. They don't become automatically included in your jar.
The reason for this is because it's wasteful under certain circumstances. Imagine you have two jars: a.jar and b.jar. Both rely on apache commons. It would probably be more efficient (space-wise) to simply have each separated and loaded from a common library directory.
If you want a so-called "fat jar" (or whatever the proper term for having all of your dependencies in one jar is), you need to use a plugin like this one: