Bug 547004 - Run class fails "Selection does not contain a main type" for simple class that has main method
Summary: Run class fails "Selection does not contain a main type" for simple class tha...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.11   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2019-05-06 09:40 EDT by Jan Peter Stotz CLA
Modified: 2023-06-03 04:49 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Peter Stotz CLA 2019-05-06 09:40:15 EDT
Using Eclipse 2019-03 I am getting the error "Selection does not contain a main type" when I try to run a class that obviously contains a main method (the code is already stripped down):

package bla;

import org.slf4j.LoggerFactory; // class from maven library
import de.appicaptor.common.logging.LogUtils; // class for other project

public class TestX {

	public void run()  {
	}

	public static void main(String[] args)  {
		TestX test = new TestX();
		test.run();
		System.exit(0);
	}

}

The class to be executed is located in a project that uses a lot of libraries via Maven (jar files from .m2 repo as well as Eclipse-Maven projects from the current Eclipse workspace). 

I narrowed it down to the import statements. If I remove  one of the two import statements the main method is found again. 

All open projects are fully compiled (no compile or other errors shown in the Problems view). All projects use the JavaSE-11 runtime (AdoptOpenJDK 11.0.3 64bit hotspot for Windows).

The Error Log view does not show anything that could be related to this problem.

Restarting Eclipse, using -clean startup option, Updating all Maven projects does not solve this problem.
Comment 1 Jan Peter Stotz CLA 2019-05-07 10:39:31 EDT
I found a workaround for this bug: When I select the main method in the "Package Explorer" tree view and execute the Run As -> Java Application command on this main method node I can execute the class without problems. 
Also the automatically generated Run configuration works.

Only when I select the class in the Package Explorer tree view and select Run As -> Java Application I still get the error message "Selection does not contain a main type".
Comment 2 Andrey Loskutov CLA 2019-05-15 15:16:17 EDT
Probably duplicate of bug 545627.
Comment 3 Eclipse Genie CLA 2021-05-12 05:31:45 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 4 Eclipse Genie CLA 2023-06-03 04:49:14 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.