3

I accidentally converted my project to Maven by going to Configure > Convert to Maven Project. Now I want to undo this. I read that I need to right click Maven > Disable Maven Nature and that worked fine. However I want to totally remove Maven, so I deleted the pom.xml and the target folder. When I try to run my code now, I get the error:

Error: Could not find or load main class

So what am I missing? How do I revert from a Maven project to a non-Maven project?

Community
  • 1
  • 1
CC Inc
  • 5,842
  • 3
  • 33
  • 64

2 Answers2

2

When you convert a Java project to a Maven project in Eclipse, the Maven Integration for Eclipse (m2eclipse) configures the Java incremental compiler to put the compiled class files in the same location as Maven would put them, i.e. target/classes.

So when you remove the Maven nature and delete the target folder, you now also have deleted the compiled class files and your project can no longer run. AFAIK, the incremental compiler doesn't detect when you remove its output files, so you need to trigger a rebuild by cleaning the project (Project > Clean...)

This will fix the problem that you can not launch your project, but may re-create a target folder. If you also want this to be "fixed", you can switch back to some other folder name for the binaries, e.g. bin, in the project's Java Build Path configuration on the Source tab.

oberlies
  • 11,503
  • 4
  • 63
  • 110
  • Ah, okay. That makes sense, thank you for clearing up that point for me :) – CC Inc Jul 12 '14 at 05:40
  • @oberlies As you suggested, I tried cleaning the project under Project –> Clean... –> Clean. Unfortunately, when I try to run the project, I still get the error message, "Error occurred during initialization of boot layer. java.lang.module.FindException: Module reasoner not found." (reasoner is the name of the only module in my project.) How do I resolve this error message? – Brian Schack Sep 27 '22 at 21:24
1

Is it basically a Maven project, i.e., do you have and maintain it through a pom.xml? Then my suggestion is to delete the project in Eclipse but keep the files on the disk (i.e., it removes it from the workspace). Then, run a simple mvn eclipse:clean eclipse:eclipse which creates a simple Java project without the Maven nature based on the POM (so the libraries are linked and the source/output directories are set up correctly - this may solve your ClassNotFoundError).

If it's a simple Java project, I would advise deleting it from the workspace, removing the .classpath and .project files and importing it again with the Create a Java project with existing sources wizard.

Either way, make a backup of your project before you start doing anything :-)

rlegendi
  • 10,466
  • 3
  • 38
  • 50
  • Thanks, the second method worked great :) I just removed the pom.xml and target folder, deleted the .classpath and .project as you advised and followed steps [here](http://stackoverflow.com/a/9280568/1482644) to import the project. Thanks! – CC Inc Jul 03 '14 at 15:39
  • If it was a Maven project, why would CC Inc want to delete the pom.xml? IMHO it is pretty clear from the question that the pom.xml was only created by accident. – oberlies Jul 07 '14 at 12:58
  • Basically there are 2 ways of working with Maven projects, Eclipse's Maven plugin or Maven's Eclipse plugin (hehe, nice namings, right?). With the the second option, you're working with a plain Java project that has no Maven nature. Each time you touch the POM you regenerate the Eclipse project descriptors. That's why I suggested the first alternative. Probably it was clear for you, but not for me -- that's why I asked :-) – rlegendi Jul 07 '14 at 14:16