获取以下构建错误:“类型{---}无法解析。它是从所需的.class文件“ [英] Getting the following build error: "the type {---} cannot be resolved. it is indirectly referenced from required .class files"

查看:167
本文介绍了获取以下构建错误:“类型{---}无法解析。它是从所需的.class文件“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我在Eclipse(Java)中有以下设置:

So, I have the following setup in Eclipse (Java):


  1. 我有一个项目(让这个项目1 )它提供了一个接口(这是包私有的)

  2. 我有另一个项目(项目2),其中包含一个项目1的包...该包中的类将包私有扩展接口项目1,并提供一个很好的公共接口。

  3. 现在,我有项目3,它引用了项目2。项目3然后使用项目2中提供的公共对象。

在项目3中从项目2调用构造函数时,我得到以下内容:

Upon calling the constructor from project 2 in project 3, I get the following:

类型{---}无法解析,它是从必需的.class文件间接引用

"the type {---} cannot be resolved. it is indirectly referenced from required .class files"

如果我从项目3添加项目1的引用,一切都很好。有没有办法以这种方式参考项目3?参考它真的没有意义。

If I add a reference to project 1 from project 3, all is well. Is there a way to NOT have to reference project 3 in this way though? It really doesn't make sense to reference it.

我正在使用Eclipse(Helios)与最新的JDK等...

I'm using Eclipse (Helios) with the most recent JDK etc...

推荐答案

这是一个传递依赖。你需要你的类路径,你所使用的任何类都需要所有类。因此,您需要在类路径中具有项目1中的类,例如,可以将它们打包为 .jar 。或者你可以去 Build Path>项目2的订单和出口,并将项目1标记为导出。

This is a "transitive dependency". You need on your classpath all classes that are required by any class you use. So you need to have the classes from project 1 in the classpath somehow - you can package them as a .jar, for example. Or you can go to Build Path > Order and Export of Project 2, and mark Project 1 as exported.

这里重要的一点是项目依赖只是一个开发好的 - 当您独立执行程序(或部署到容器)时,Eclipse项目依赖关系已经消失。所以你必须确保你的依赖被满足。

An important thing here is that the project dependencies are a mere development "goodie" - when you execute the program standalone (or deploy it to container), the Eclipse project dependencies are gone. So you must ensure your dependencies are met.

这篇关于获取以下构建错误:“类型{---}无法解析。它是从所需的.class文件“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆