简体   繁体   中英

Eclipse error: “The import … cannot be resolved”

I know I am asking the very popular question. But I can not find the solution to the problem. I have a sandbox to which I added a code of the unit test MulticurveBuildingDiscountingDiscountAUDTest.java file and commented it.

Then I added the main method and I could successfully run the program (print something in a console).

Finally, I uncommented the code of the MulticurveBuildingDiscountingDiscountAUDTest.java file and I saw the following error:

The import com.opengamma.analytics.financial.instrument.index.GeneratorSwapFixedONMaster cannot be resolved.

And further in the code:

GeneratorSwapFixedONMaster cannot be resolved

I know that this import is located in the og-analytics src/test/java location, which I believe is not listed anywhere in the build path. I believe the problem is with a build path options and specially with classes like GeneratorSwapFixedONMaster which were created specially for tests. I have been playing around with cleaning, rebuilding projects, reinstalling and as a result updating the JRE. I have visited these Import *** cannot be resolved [duplicate] and these Eclipse error: “The import XXX cannot be resolved” questions. Do you know what shall I do to cure the following error?

I have many problems with other imports from the original MulticurveBuildingDiscountingDiscountAUDTest.java file as well.

Update : #1 is a location of my file. #2 is the location of classes this project uses. The MulticurveBuildingDiscountingDiscountAUDTest.java file is taken from the src/test/java

屏幕截图

Update 2 : one may see that in Libraries I have included all the dependencies I might need (at least I do not know what else to add). The Maven Dependencies contains the hole og-analytics package:

屏幕截图2

I know that this import is located in the og-analytics src/test/java location, which I believe is not listed anywhere in the build path.

Perfectly explains your problem. In order to import any class, you must either have the source in your build path, or some directory that contains a compiled version of that class. It is that simply.

The answer is: get clear on your project setup. If you intend to use classes from somewhere, you have to make them available somehow. Otherwise it will not work. In your case: if your tests want to make use a certain thing - then you should probably add that "thing" to your test project (you should avoid putting test-only stuff to your "product" projects).

That is all there is to this.

You included the source ( src ) folder og-analytics/src/main/java which contains the *.java files instead of the classes ( bin or classes ) folder with the *.class files (in your case, probably og-analytics/target/classes ).

But instead using Add Class Folder... you should add the project og-analytics in the tab Projects . Or even better, in the Maven pom.xml file add the dependency to the project og-analytics like you did for og-util .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM