Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Launch config "Error: Could not find or load main class"; class is in a dependent mvn proj
Launch config "Error: Could not find or load main class"; class is in a dependent mvn proj [message #1799800] Thu, 13 December 2018 11:38 Go to next message
Eclipse UserFriend
Hello,

Context:
I have "projectA" which depends on "projectB". Both are maven projects. In "projectB" there is a "com.myproj.Main" launchable class.

1) "com.myproj.Main" can be launched without problems IF the corresponding launch config references project "projectB" (in launch config properties/Main (tab)/Project (textbox). OK until now.


2)
If I now modify the launch config, changing it's project to "projectA" => I get the ERROR: "Error: Could not find or load main class com.myproj.Main". This class exists in the classpath (cf. maven). However I think that the process isn't even launched.

3) If I create in "projectA" a class, say "Main1" (w/o a "main" method), and modify the launch config so that it launches "Main1" => it works.

Have you got any hints for me?
Thanks in advance.
Cristian.

[Updated on: Thu, 13 December 2018 11:39] by Moderator

Re: Launch config "Error: Could not find or load main class"; class is in a dependent mvn [message #1799805 is a reply to message #1799800] Thu, 13 December 2018 15:53 Go to previous messageGo to next message
Eclipse UserFriend
I come with an update. I manage to inspect the classpath of the java process in both cases. When the launch config uses a class from another project (i.e. "projectB"), the classpath is incorrect; it contains mainly the jre libs + the /target/classes dir.

So it seems that when the target class is in the other project, the maven logic doesn't seem to do it's job, i.e. to populate the class path with entries from both the repo AND the workspace.
Re: Launch config "Error: Could not find or load main class"; class is in a dependent mvn [message #1799810 is a reply to message #1799805] Fri, 14 December 2018 00:52 Go to previous messageGo to next message
Eclipse UserFriend
Hi,
That is how launch configurations are designed to work.
It is not sufficient to be present in the classpath, the main class should be part of launch config properties/Main (tab)/Project (textbox).
Re: Launch config "Error: Could not find or load main class"; class is in a dependent mvn [message #1799817 is a reply to message #1799810] Fri, 14 December 2018 03:08 Go to previous message
Eclipse UserFriend
Thanks for your answer.

From what I observed, the launch config does allow the main class to be somewhere on the classpath but not necessarily directly in the main project (i.e. the project specified in the launch configs properties/Main (tab)/Project (textbox).

I'm saying this because I have just tested the same configuration (i.e. projectA, projectB, in projectB: com.myproj.Main, launch config references projectA), but this time, the projects were plain Java projects, instead of Maven projects (where projectA depends on projectB via configuration in the Build Path/Projects tab).

This strengthens my feeling cf. my previous post, i.e.:
Quote:
o it seems that when the target class is in the other project, the maven logic doesn't seem to do it's job, i.e. to populate the class path with entries from both the repo AND the workspace.


I think it's related to the following line in the ".launch" file:
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/>



Previous Topic:Eclipse crashes with ACCESS VIOLATION exception
Next Topic:Linking java files
Goto Forum:
  


Current Time: Sat Aug 30 17:37:01 EDT 2025

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

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

Back to the top