2

这可能需要一点时间来理解,但我会尽量让它尽可能简单。我在 Netbeans 中有以下项目(更改名称以保护无辜者):

  1. 组件1
  2. 组件2
  3. 更细

Component1、Component2 和 Thinger 都需要 Core,因此在其库中包含指向该项目的链接。

Thinger 还需要 Component1。

Component1 还需要 Component2。

每个项目都自行编译(仅包含参考)。但是,一旦我在 Component1 内创建 Component2 的实例,我就会在运行时收到以下错误:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: somepackage.stuff/Component2

请记住,所有项目都继续构建得很好,我很难过。我没有使用反射,只有当我在 Component1 中包含 Component2 someVar = new Component2() 行时才会发生这种情况。知道什么可能导致这种情况发生吗?

更新 #1:在构建 Thinger 时,它似乎并没有拉入 Component2 的 jar。有没有办法可以强制 Netbeans 这样做?

4

1 回答 1

1

Simply add a dependency to Component2 in Thinger. Many times components will have dependencies that aren't necessarily require for runtime (could be optional functionality, for example), but only for building. So, simply add the extra dependency to Thinger and it will be all good.

于 2012-04-08T18:34:06.557 回答