10

I'm using Eclipse version Oxygen.2 Release (4.7.2) with M2E version 1.8.2.20171007-0217 on Windows 7.

When I define a new RUN configuration I can see the Maven dependencies of the Main project (the one defined in the Main tab of the "Run Configurations" dialog) in the Classpath tab.

However, I cannot add the Maven dependencies of the other projects that I added to the Classpath tab, under "User Entries". The result is that I get ClassNotFoundException. To solve that, I need to explicitly add the external JARs from my local .m2 repository.

I googled around to see if I could find a solution but I could not find anything useful.

Is it possible to do what I am trying to do, i.e. adding the maven dependencies of all the projects added to the Classpath tab to the classpath? How can I do that?

vindev
  • 2,240
  • 2
  • 13
  • 20
Claves DOA
  • 111
  • 7
  • " I cannot add the Maven dependencies of the other projects that I added to the Classpath", are these you projects, and are they added to each others build path? – Elydasian Jan 22 '18 at 09:37
  • 1
    _Maven Dependencies_ are associated with a project (updating a project's `pom.xml` will also change the _Maven Dependencies_). Therefore you have to add the projects as dependencies to your run configuration. – howlger Jan 22 '18 at 09:47
  • @newbie All other projects added to the classpath are my projects. They have their own dependencies, different from the main project dependencies. But I cannot add to each others build path otherwise a cycle in the build dependencies is detected – Claves DOA Jan 22 '18 at 11:17
  • @howlger the projects are added as dependencies to the run configuration. However, their own maven dependencies are not. The main project acts like a controller (engine), which runs the code defined in the projects added to the classpath. Since their maven dependencies are not visible to the main controller, the ClassNotFoundException is thrown. – Claves DOA Jan 22 '18 at 11:22
  • @Claves DOA Are the other projects added to the local .m2 repository? – Elydasian Jan 22 '18 at 12:12
  • Create a separate Maven project for their own Maven dependencies to use it in the run configuration (to resolve Maven dependencies you need a project). – howlger Jan 22 '18 at 12:19
  • @newbie No, they are source projects. If I understand your question. – Claves DOA Jan 22 '18 at 13:01
  • 2
    @howlger that looks a bit complicated. I do not want to create new projects or change a setup (dependencies in pom.xml files) that runs already successfully in production. My goal was being able to setup all in Eclipse to run it locally. I hoped that it could be achieved via some "magic" of the IDE with the push of a button. – Claves DOA Jan 22 '18 at 13:04
  • I have not really understood the use case for this manual adding of projects to the class path. Could someone explain to me why it is better to add them to the run configuration instead of defining them as Maven dependencies. Is it to dynamically run things which are found on the class path without knowing them at compile time? – J Fabian Meier May 15 '20 at 09:19

2 Answers2

3

No not possible. Or if it is possible - it is not correct to do so. If you use maven, you need to add those dependencies to the pom.xml of you project.

ACV
  • 9,964
  • 5
  • 76
  • 81
  • 3
    I cannot add those dependencies to the pom.xml of the main project since they are specific to the projects added to the run configuration classpath tab. The main project is an engine/controller which task is to run the code of the added projects. I think it should inherit the mvn dependencies of the added projects, otherwise it cannot find the added projects own dependencies. Not sure if it's clear. – Claves DOA Jan 22 '18 at 11:27
1

Ok, here is a solution I found and it worked for me.

First, I removed each project from the others build path, this way, they don't see each other.

Then in eclipse, I converted the projects to maven, and got the pom.xml file(s)

Then, I installed the projects with: mvn install. This way, I got the projects into my local repository and could add them as dependencies to my other projects pom file

Elydasian
  • 2,016
  • 5
  • 23
  • 41