Community
Participate
Working Groups
When a Java project (using the Java Builder) contains an AspectJ (.aj) file, and AJDT is installed, Eclipse tries to compile this file with the plain Java compiler, which fails. In our project, we optionally enable AspectJ. This project contains an .aj file, which should only be used when AspectJ is enabled (and the project is build with the AJ-builder). However, on systems with AJDT installed, this file is also compiled for plain Java projects. This project does not have the AspectJ nature, nor does it use the AJ-builder.
This is the expected behavior. *.aj files are set up as "Java-like" files so that they can be handled similarly to Java files in places like the package explorer, outline view, search, etc. However, the side-effect of this is that *.aj files will be sent to the java compiler by default. The solution is to select all of your aspect files right-click -> Build Path -> Exclude. This will exclude all of your aj files from building. If you add the AJ nature to your project, then all of these files will automatically be included again. Removing them will automatically exclude them. So, although the behavior is not exactly as you would like, there is a reasonable work around.
We generate the build path with the Maven Eclipse plugin, therefore it is not practical to manually edit the it; the next time you run mvn eclipse:eclipse, your change will be reverted. For some reason, it is not possible to use sourceExcludes in our pom. The problem is that the .aj files are also seen as 'Java-like' for projects without the AJ nature. Isn't it possible to only register them as 'Java-like' for projects with the AJ nature?
Unfortunately, the answer is no. JDT caches the java-like file extensions for the entire workspace after calculating them once. Two possibilities: 1. Can you put your aspects in src/aspectj? It's possible that mvn eclipse:eclipse will not generate an source folder for it and if it does, then it is easier to exclude a single folder than individual source files. 2. Have you considered m2eclipse? It provides much better knowledge about AspectJ and may make things work better.
Ok, that's unfortunate. The first option seems like a good solution for now. I'll see if that will work for us. I think, I'll also file a bug report for the problems with the sourceExcludes for the maven-eclipse-plugin. We've tried m2eclipse several times, and failed miserably. It just can't cope with large, multi-module projects with complex inheritance structures in the poms and different Maven profiles. We try it every now and then to see if there is any improvement, but it simply isn't up to the task for our project. Last time, it only took several hours of development until all dependencies of the project were broken beyond repair. Somehow all project dependencies got inverted and nothing helped to get them right again. Since then, our project only has become much more complex and little seems to have been done on m2eclipse. Perhaps we'll give it another try in a few months.
Hmmmm...I suppose I could provide a command to automatically exclude all .aj files from a Java project.