0

I have two maven projects in eclipse, a jar and a war. The war has a dependency on the jar, which is resolved through workspace resolution.

The problem is that the jar has generated classes, which are added to the jar through build-helper-maven-plugin. But these classes aren't being properly resolved in the war project. For example: It auto-completes the class but keeps saying it can't be found. More importantly, when running glassfish through eclipse, I get a class not found for these classes.

If I disable workspace resolution everything works fine, but I hope to use workspace resolution. Any ideas?

EDIT: Folder structure. The maven workspace resolved persistence project in the lower image is in the Maven Dependencies folder, essentially your seeing the top and bottom of the folder.

enter image description here

Workspace Resolution

nilacqua
  • 167
  • 3
  • 15
  • Show more of project structure. It does not look like maven dependencies at all. You can blur/cut the names, I dont care, just want the structure. – Antoniossss Jan 21 '16 at 01:49

1 Answers1

2

IDK if I am correct, but you are talking about Eclipse problems - it does not "see" generated classes right?

To fix it, you have to add generated sources directory to the eclipse's build path and it should fix your problem.

  1. Right click on project that has generated classes->buildPath->conf buildpath
  2. In source tab - click add folder
  3. Select the directory where build helper generates java files.

Generated classes will apear as additional source folder in Eclipse's project hierarchy and voila, Eclipse can autocomplete and resolve generated classes now on the same conditionstha any it would on any other class written by you in the same project by hand.

Antoniossss
  • 31,590
  • 6
  • 57
  • 99
  • The generated folder is on the build path and eclipse can resolve within the same project, the problem is for projects that are linked by maven resolutions, those other projects can't see the generated classes – nilacqua Jan 19 '16 at 16:54
  • You will have to include POM for `jar` project, as for some strange reasons you are not getting your generated classes included in producted jar. Can you confirm that those classes are actually in the generated `.jar` file? – Antoniossss Jan 19 '16 at 17:02
  • The classes are in the jar. If I turn off workspace resolution or drop the war in the server, everything works fine. It's something about workspace resolution – nilacqua Jan 19 '16 at 17:12
  • Indeed as classes are in jar. Rather obvious, but i must ask. Is you lib (jar project output) listed as maven dependency in eclipse? I am not talking about POM file here, In project view (project explorer) there is lib called Maven Dependenices. Expand it and tell me is it there. You can expand those as well. If the jar is there and if you expand it you can see classes file inside - new eclipse installation. You can try to create different workspace and import your projects there. Sometimes eclipse requires black magic indeed ;( – Antoniossss Jan 19 '16 at 23:46
  • Since I'm using workspace resolution between the maven projects, it only shows an open folder for the depended project in the lib folder which can't be drilled into. This doesn't mean the project is empty; as far as I've seen this is an general feature of workspace resolution. – nilacqua Jan 20 '16 at 17:37
  • So you are not using maven plugin and you have not `Maven Dependencies` as library dependecny in your project? – Antoniossss Jan 20 '16 at 17:41
  • Sorry if I mispoke, I do have the maven plugin and the Maven Dependencies lib. I have all my dependencies in the maven dependencies folder, including the one in question. The one in question, since it's a workspace resolution, can't be drilled into, but all the classes except the generated ones are accessible. – nilacqua Jan 20 '16 at 17:46
  • And I asked are the classes visible in the maven dependencies - are they? If so, `Project->clean->all` should rebuild classes files and should work – Antoniossss Jan 20 '16 at 17:48
  • I've included in the Original Post what a Eclipse Maven Workspace Resolution looks like. It doesn't allow you to see into the project from the Maven Dependencies Lib Folder. Tried cleaning everything again, no difference. – nilacqua Jan 20 '16 at 19:24
  • Projects are not included as maven dependencies so I am not asking about it (and never were), what I as if you are including your dependant project as maven dependency as well and you can see that in the project explorer. – Antoniossss Jan 21 '16 at 01:48
  • The dependent project is included as a maven dependency. I see it in the project explorer as its own project and in the maven dependencies folder as shown in the Original Post image. – nilacqua Jan 21 '16 at 23:39
  • I'm just going to mark this as the correct answer because it has a lot of good ideas. I think ultimately the issue was that after setting the build path, I maven updated the project, which turned off the additional build path. After maven updating, you need to reset the build path. For some reason this didn't show as not in the build path for a few days, but then the error persisted. – nilacqua Feb 01 '16 at 21:21