AspectJ causing "Editor does not contain a main type" error

793 Views Asked by At

After installing the AspectJ Development Tools into Eclipse, the "Run" button and the Ctrl-F11 shortcut both become nearly useless: using them (or the Debug button) will throw an "Editor does not contain a main type" error message, even for projects that do not require a main type to be present (eg. Android application projects). Standalone Java projects with a proper main type defined work fine - so it seems AJDT is forcing Eclipse to check for a Java main() without checking the project type first. Whether or not the project is an AspectJ project makes no difference, either.

The problem only appears when the file you are currently editing has either ".java", ".aj" or ".class" anywhere within its filename (note: it doesn't actually have to end with those extensions, as long as it's anywhere in there - readme.txt will work, readme.java.txt won't).

Two ways I've found to work around this - regardless of whether or not it's an AJ project - after installing AJDT is:

  • Select a file within your project in the Package Explorer whose name doesn't contain .java, .class or .aj, and then hit Run (the Package Explorer has to remain active and selected).

  • Create a new Run Configuration for your project, and use it to launch your project. This still adds a pointless extra step, as well as being impractical for those who work with a lot of projects.

I've tried this on both Eclipse Juno and Helios (Windows XP x86 as well as Win7 x64), the result is the same. While it might seem like nitpicking it certainly isn't: AJDT is hijacking the most frequently used function of the IDE.

I've resorted to having two different Eclipse installations with their own separate workspaces on my work PC, one with AJDT installed, and one without, so I can use the IDE properly when I'm not working on anything AJ-related. Since my company is working on a project that would require other developers to install AJDT into their IDEs, this is a significant issue for us that goes beyond our own loss of time - I can't imagine a lot of developers would be willing to put up with a significant bottleneck being added to their workflow for absolutely no reason at all. So most likely, they will just ditch our product instead!


Update: This has been identified to be a bug inside AspectJ, and has been reported to the AJ development team. You can keep track of it here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=399660 As of this writing, the bug has already been partially fixed, restoring Run functionality to non-AJ-enabled projects.

1

There are 1 best solutions below

1
On

I was just coming on this site to ask the same question. While I don't have an answer for why this is going wrong, I have a workaround which is helping me currently:

Go to Preferences > Run/Debug > Launching and select Always launch the previously launched application. This will introduce bearable behaviour when working on a single project. You will need to manually create a run configuration for your main class.