1

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

screenshot

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:

screenshot 2

howlger
  • 31,050
  • 11
  • 59
  • 99
Eugen
  • 33
  • 1
  • 1
  • 7
  • Is it a Maven project? Could you give an example: in which class the import cannot be resolved and where is this class located (in `src/main/java` of the project `og-analytics`)? Where is the missing class (in `src/test/java` of the same project, in a different project, in a JAR or Maven dependency, ...)? – howlger Nov 29 '17 at 14:50
  • Dear @howlger, I have included update. All projects are using Maven. – Eugen Nov 29 '17 at 18:27
  • Why is your MulticurveBuildingDiscountingDiscountAUDTest unit test located in the `src/main/java`? Tests should be in `src/test/java`. Also you will not going to see files in `src/test/java` in other modules it will be run during the build, but the class files will not be in the final jar, therefore you cannot refer classes in src/main from src/test (you can do the other way around only). – helospark Nov 29 '17 at 19:21
  • To solve given issue Please follow below link [stackoverflow.com/a/48381463/5093657](http://stackoverflow.com/a/48381463/5093657) – Balkrushna Patil Jan 22 '18 at 12:26

2 Answers2

1

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.

howlger
  • 31,050
  • 11
  • 59
  • 99
  • I was playing with howlger and @GhostCat suggestions and other ideas I found in the internet. I do not know what has happened. I made too much changes, I believe that updating Maven finally solved the issue. – Eugen Nov 30 '17 at 21:00
0

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.

GhostCat
  • 137,827
  • 25
  • 176
  • 248
  • dear @GhostCat, I have updated the question. From the second screenshot you may see that I am using all needed libraries: explicitly stated og-analytics/src/test, in Maven Dependencies I have og-analytics and rest of jar-s. – Eugen Nov 29 '17 at 18:30