Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Cannot find Main class from test classpath(Exclude test code is NOT checked but test classes are missing)
Cannot find Main class from test classpath [message #1801738] Fri, 25 January 2019 12:20 Go to next message
Alex Mising name is currently offline Alex Mising nameFriend
Messages: 149
Registered: March 2010
Senior Member
Hello,

I am using 2018-09 on Windows with a Maven multi-module project.

I created a launch configuration of type "Java Application" (using Java 8 for it).

In the classpath tab, I have NOT checked "Exclude test code" because I want to launch a main class that is actually coming from a Maven test classpath dependency.

However, when I try to launch it, I get the error:

Error: Could not find or load main class my.test.classpath.Main


Now, looking at the "Show Command Line" output I can see that target/test-classes and Maven's test-scope dependencies are NOT present.

Any idea what I am doing wrong?
Re: Cannot find Main class from test classpath [message #1801827 is a reply to message #1801738] Mon, 28 January 2019 07:09 Go to previous messageGo to next message
Till Brychcy is currently offline Till BrychcyFriend
Messages: 3
Registered: May 2016
Junior Member
M2E has implemented test classpath seperation before the concept was added to JDT and it doesn't use this checkbox yet.

It uses a heuristic (see org.eclipse.m2e.jdt.internal.launch.MavenRuntimeClasspathProvider.getArtifactScope(ILaunchConfiguration)) :

When JUnit and TestNG Tests are launched, the test scope is used.
When a Java Application is run, it checks if the main class is from a test source folder. If yes, it uses the test scope, otherwise the main scope.

So if your main is in a binary test dependency, this goes wrong.

As workaround, you could create a main method in a test source folder that just delegates to the actual main method you want to launch.

You can help by creating a bug report about this at bugs.eclipse.org (product=m2e, component=jdt)

[Updated on: Mon, 28 January 2019 07:10]

Report message to a moderator

Re: Cannot find Main class from test classpath [message #1809403 is a reply to message #1801827] Mon, 15 July 2019 17:14 Go to previous message
Alex Mising name is currently offline Alex Mising nameFriend
Messages: 149
Registered: March 2010
Senior Member
In the interest of future reference, this is now: https://bugs.eclipse.org/bugs/show_bug.cgi?id=548948

I am trying to contribute the fix.
Previous Topic:Recreating an image in CSS with flexbox
Next Topic:spaces/tabs settings not working
Goto Forum:
  


Current Time: Wed Sep 25 21:35:59 GMT 2024

Powered by FUDForum. Page generated in 0.03616 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top