Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
784 views
in Technique[技术] by (71.8m points)

java - Getting the following build error: "the type {---} cannot be resolved. it is indirectly referenced from required .class files"

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

  1. I have a project (lets call this "project 1") which provides an interface (which is package private)
  2. I have another project ("project 2") which contains a package from project 1... Classes in this package extend the package private interfaces in "project 1" and provide a nice public interface.
  3. Now, I have "project 3" which references "project 2". Project 3 then uses the public object provided in project 2.

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

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

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.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...