2

I migrated my workspace from Eclipse to Intellij, in Intellij I have a project build from two modules, the run configuration are set on one module but the main class is in the second one.

in Eclipse it works fine, but in Intellij I get "Error: Could not find or load main class [class name]".

I created a dependency in the project structure, and played a lot with the running configurations which didn't help.

Any ideas? does any one have an experience with this structure in intellij?

Adding more details:

  1. I imported two eclipse projects to intellij - UI project which uses a jar from core project.
  2. The two projects are depended, my goal is to run the UI project which use a jar from the core project, and be bale to debug in the IDE the code
    from both projects.
  3. In Eclipse it is done by adding the core project to the classpath in the debug configuration classpath before the UI (running) project.

In intellij I added runtime dependency between the projects which didn't work. The project is running but from the Jar and not from the code of the second project - so I can't debug the code.

Add Run Configurations - Run Configrations

The main class is in the core project, I tried to delete the created core jar from the classpath of the UI project and run it with module dependency, but it failed on main class not found error.

Ideas?

Thanks

yoavba
  • 401
  • 2
  • 6
  • 13
  • 1
    Select the module which has the main class and specify this class to run. This module can depend on another one if needed. – CrazyCoder Jun 14 '17 at 11:33
  • It didn't help still getting the "Error: Could not find or load main class", in the eclipse I run the depended project with main class from the second one, where in the classpath the second project (where the main class is) was first – yoavba Jun 14 '17 at 18:35
  • Please share the [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – CrazyCoder Jun 14 '17 at 18:39
  • Could you perhaps post your run-configuration from intellij? And in which Project is your main-class? UI i assume? – trappski Jun 15 '17 at 09:50
  • Added an image of the run configurations, the main class is in core project, in eclipse it is enough that the core project is set before the UI in the configurations classpath, tried that in intellij but didn't work – yoavba Jun 15 '17 at 10:50
  • As long as core is a properly set up dependency on the UI module that should work. intelliJ should warn as soon as you try to select a class it can't find on the classpath while setting up the configuration. Have you verified that the proper jar is in fact on the classpath when you run? You can see the exact command including the classpath used in it's entirety just by clicking on the top-line in the run window . – trappski Jun 15 '17 at 11:16

2 Answers2

0

OK got it - the Core jar should be in the dependencies in compile scope, as well as the module in provided scope, the main class can be from the core project and it works. Thanks to all respondents

yoavba
  • 401
  • 2
  • 6
  • 13
0

"The project is running but from the Jar and not from the code of the second project - so I can't debug the code."

I was also looking to do this. Your answer is not that clear. Here's what I did and it worked in my case,

Project Structure (Alt+Shift+S)

> Modules

> on the Sources tab for the module that has dependencies, look on the right side,

click the + Add Content Root, then add the src folder of the dependency project.

I was able to then put breakpoints in those src files and IntelliJ would step to them in debugging.

(Note you may see the warning "Alternative source available for the class ...")


Reference

From https://www.jetbrains.com/help/idea/creating-and-managing-modules.html,

"Modules normally have one content root. You can add more content roots. For example, this might be useful if pieces of your code are stored in different locations on your computer."

(see also How to debug a project in Intellij while setting the breakpoints in another project)

TT--
  • 2,956
  • 1
  • 27
  • 46