arcy arcy - 5 days ago 5
Java Question

Moving from NetBeans to eclipse, can't seem to find generated java files

I have been developing in NetBeans, I am exploring changing over to eclipse.

We have a set of directories for the modules in our project; we have scripts that check things out of Subversion and do other things with that directory tree, and we have NetBeans access the sources, etc., from that directory tree.

All our modules are built, etc., with Maven. All of this works fine from within NetBeans.

I have successfully imported all the projects into eclipse (File / Import / Maven), but evidently something is different in the handling of "generated sources". We have some castor-generated files in one module, and jaxb-generated files in another. The generated files in both cases are not found by the compiler, and therefore these modules have compile errors.

Maven is configured to generate the Java classes which cannot be found; maven clean deletes them and maven compiler:compile puts them back. But in eclipse those java files cannot be found for compiling other classes, but in NetBeans they can.

I tried deleting the generated java files, then rebuilding in eclipse; the java files were regenerated in generated-sources, but still cannot be found by the compiler when it comes time to compile (or syntax-highlight) my code.

It sort of looks like a classpath issue, but we don't set the classpath in NetBeans for a maven project. How should I configure things in eclipse so the generated class files are found?

Answer

In Eclipse in the Package Explorer right click the project folder which contains the missing files. Goto "Build Path >" then "Configure Build Path...". Properties for your project folder will open. Click on the "Source" tab. Then click on the "Add Folder..." on the left. A source folder selector box opens, here select your folder which contains the auto generated sources. Normally it will be in the target directory. Then press ok. If this will not work, try one directory deeper or less deep.

If there is no target directory, build the project folder with maven on a shell.

The generated-sources directory will be stored in the .classpath file in your project folder.

HTH.