Search code examples
eclipsem2eclipse

Eclipse, mvn eclipse:clean eclipse:eclipse, Error: Could not find or load main class


Problem : Error: Could not find or load main class

Situation :

  1. Spring Boot Project
  2. Latest Version of Eclipse, Maven 3.3.1, JDK 1.8.0.242
  3. Windows 10
  4. Eclipse Build 2019-12

How to reporduce

  1. Go to parent of my project
  2. Run mvn eclipse:clean eclipse:eclipse
  3. Import the projects as Existing projects in workspace ( I do not want to use Maven Project )
  4. Go to my main class
  5. Right Click Run -> Run As -> Check the Main Class its correct
  6. Error: Could not find or load main class

Already tried :

  1. Many times clean run mvn clean install mvn eclipse:clean eclipse:eclipse
  2. Delete .meta and recreate workspace many times
  3. Went to Run as -> Classpath -> Advance -> Add Folder -> Add target/classes
  4. Since I am writing this question, I apparently tried everything on StackOverflow related to this issue.

I appreciate if someone can recommend something new .

[ Update ]

The problem is resolved for all the builds other than 2019-12. I have verified for the following

  • Eclipse 2019-09 (4.13)
  • Eclipse 2019-06 (4.12)
  • Eclipse 2019-03 (4.11)

Solution

  • This question convinced me. This only happen 2019-12.
    I have verified for the following.

    • Spring suite 3
    • Spring suite 4
    • Eclipse Photon

    The cause of the problem is due to restrictions on classpaths that are limited by OS.
    - This is a one of related with this issue Java: Support for long classpath on Windows.

    You can solve the problem by setting the options for the classpath as shown below.(or from here ) enter image description here In Spring Tool Suite 3,4 it works without any special configuration.

    I haven't found a way to visually identify the problem yet.

    This problem is unique.
    There's nothing wrong with builds or deploys, it's only a problem when debugging.
    So it's easy to tell if it's a problem with the classpath or not.